Attribute VB_Name = "modFXRSTransactions"

'---------------------------------------------------------------------------------------
'Module : modFXRSTransactions
'Date   : 03/17/2004
'Author : Chris Elwell
'Purpose: Contains routines for building and sending FXRS transactions.
'---------------------------------------------------------------------------------------

Option Explicit
Option Compare Text

'---------------------------------------------------------------------------------------
' Module    : TransactionBuilder
' DateTime  : 8/03/2003
' Author    : Tim Johnson
' Modified  : Chris Elwell
' Mod Date  : 2/18/2004 - Field not added to transaction string if strFieldValue = ""
'             Also had to change FieldNumber data type from Int to String to allow for
'             multiple occurrence fields.
'             4/6/2004 - added line to remove double quotes from data.
' Purpose   : Function To Build Transactions - pass in a string variable, field number,
'             and data. The field and data are formatted and then the original
'             ByRef strTransactionString is modified.
'---------------------------------------------------------------------------------------
'
Public Function TransactionBuilder(ByRef strTransactionString As String, ByVal strFieldNumber As String, ByVal strFieldValue As String)
    On Error GoTo EH
    
    If (strFieldNumber = "99" Or strFieldValue <> "") Then
        'Remove double qoutes from data
        strFieldValue = Replace(strFieldValue, Chr(34), "")
        ' 2013-01-08, JFW, Remove French chars
        strFieldValue = FrenchConv(strFieldValue)
        strTransactionString = strTransactionString & strFieldNumber & "," & Chr(34) & strFieldValue & Chr(34)
    End If
    
    Exit Function
EH:
     MsgBox Err.Description, vbCritical, "modFXRSTransactions:TransactionBuilder"

End Function
'---------------------------------------------------------------------------------------
' Module    : TransactionParser
' DateTime  : 8/03/2003
' Author    : Tim Johnson
' Modified  : Chris Elwell
' Mod Date  : 8/26/2004 - added code to look for CRLF + "P1" + CRLF for the Eltron buffer
' Purpose   : Parse a field value from a transaction string
'---------------------------------------------------------------------------------------
'
Public Function TransactionParser(ByRef strTransaction As String, ByRef strFieldNumber As String)

    Dim strSearchChar As String     ' Field To Search For W/ Double Quotes
    Dim intStartPos As Integer      ' Field Value Start Position
    Dim intEndPos As Integer        ' Field Value End Position
    Dim intLen As Integer           ' Field Value Length
    Dim strError As String          ' Error string
    
    On Error GoTo EH
    
    'Set the string to search for
    If strFieldNumber = "0" Then
        strSearchChar = strFieldNumber & "," & Chr(34)
    Else
        strSearchChar = Chr(34) & strFieldNumber & "," & Chr(34)
    End If
    'Set the starting position
    intStartPos = InStr(1, strTransaction, strSearchChar, 1)
    ' If Field Not Found Return ""
    If intStartPos = 0 Then
        TransactionParser = ""
    Else
        'Eltron buffer contains double quotes so search for end characters
        If strFieldNumber = "188" Or strFieldNumber = "411" And InStr(1, strTransaction, vbCrLf + "P1" + vbCrLf) > 0 Then
            intStartPos = intStartPos + Len(strSearchChar)
            strSearchChar = vbCrLf + "P1" + vbCrLf
            intEndPos = InStr(intStartPos, strTransaction, strSearchChar, 1)
            intLen = intEndPos - intStartPos + 4
            TransactionParser = Mid(strTransaction, intStartPos, intLen) 'Final Field Value
        Else
            intStartPos = intStartPos + Len(strSearchChar)
            strSearchChar = Chr(34)
            intEndPos = InStr(intStartPos, strTransaction, strSearchChar, 1)
            intLen = intEndPos - intStartPos
            TransactionParser = Mid(strTransaction, intStartPos, intLen) 'Final Field Value
        End If
    End If
    
    Exit Function
EH:
     MsgBox Err.Description, vbCritical, "modFXRSTransactions:TransactionParser"

End Function
'---------------------------------------------------------------------------------------
' Module    : BuildCommonFlds
' DateTime  : 3/9/2004
' Modified  : 11/15/2004 Added Signature Required flag
' Author    : Chris Elwell
' Purpose   : Builds and returns the common fields for all transaction types.
'---------------------------------------------------------------------------------------
'
Public Function BuildCommonFlds() As String
    Dim strTrans As String
    Dim rsPreassign As New ADODB.Recordset  'Used to lookup pre-assign trk#s
    Dim strQuery As String                  'Pre-assign query
    Dim i As Integer                        'Counter for pre-assign occurrence
    '05/09/06 Added for DIM switching
    Dim strDIMs() As String
    
    On Error GoTo EH
    
    'Build the FXRS transaction
    strTrans = ""
    TransactionBuilder strTrans, 0, "020"                            'Transaction type
    TransactionBuilder strTrans, 1, g_str1                           'Transaction ID
        
    'Added 3/2/05 for pre-assign
    strQuery = "SELECT * FROM PreAssign WHERE f1 = '" & g_str1 & "'"
    ' 2008-04-10, JFW
    'strQuery = strQuery & " AND Workstation = '" & g_strComputerName & "'"
    
    rsPreassign.Open strQuery, g_connFSMSClient, adOpenStatic, adLockBatchOptimistic
    
    'Loop through pre-assign recordset and add fields
    i = 1
    Do Until rsPreassign.EOF
        TransactionBuilder strTrans, "1221-" & Trim(Str(i)), "Y"                       'Preassign flag
        TransactionBuilder strTrans, "1222-" & Trim(Str(i)), rsPreassign!f29           'Trk# for preassign
        If g_str1222 = "" Then
            g_str1222 = rsPreassign!f29
        End If
        Select Case rsPreassign!Type
            Case "Express US Domestic"
                TransactionBuilder strTrans, "1223-" & Trim(Str(i)), "0201"           'Form ID
            Case "Express Intl Master"
                TransactionBuilder strTrans, "1223-" & Trim(Str(i)), "0430"           'Form ID
            Case "Express Intl MPS"
                TransactionBuilder strTrans, "1223-" & Trim(Str(i)), "0441"           'Form ID
            Case "Express COD Master"
                TransactionBuilder strTrans, "1223-" & Trim(Str(i)), "0301"           'Form ID
            Case "Express COD MPS"
                TransactionBuilder strTrans, "1223-" & Trim(Str(i)), "0261"           'Form ID
            Case "Canada"
                TransactionBuilder strTrans, "1223-" & Trim(Str(i)), "0451"           'Form ID
        End Select
        TransactionBuilder strTrans, 1224, rsPreassign!f28           'COD Return Trk# for preassign
        TransactionBuilder strTrans, 1225, rsPreassign!f527          'COD Return Form ID for preassign
        
        rsPreassign.MoveNext
        i = i + 1
    Loop
    
    TransactionBuilder strTrans, 50, g_str50                         'Country - 2 character code
    TransactionBuilder strTrans, 12, g_str12                         'Recipient Contact
    TransactionBuilder strTrans, 11, g_str11                         'Recipient Company Name
    TransactionBuilder strTrans, 13, g_str13                         'Recipient Addr1
    TransactionBuilder strTrans, 14, g_str14                         'Recipient Addr2
    TransactionBuilder strTrans, 15, g_str15                         'Recipient City
    TransactionBuilder strTrans, 16, g_str16                         'Recipient State
    TransactionBuilder strTrans, 17, g_str17                         'Recipient Zip
    TransactionBuilder strTrans, 18, g_str18                         'Phone - Using shipper phone
    TransactionBuilder strTrans, 440, g_str440                       'Residential flag
    '03/28/06 Only include DV if not blank
    If g_str26 <> "" Then
        TransactionBuilder strTrans, 26, Trim(Str(CLng(Val(g_str26))))                      'Declared Value
    End If
    TransactionBuilder strTrans, 32, g_str32                                            'Shipper Contact Name
    TransactionBuilder strTrans, 4, g_str4                                              'Shipper Company Name
    TransactionBuilder strTrans, 5, g_str5                                              'Shipper Addr1
    TransactionBuilder strTrans, 6, g_str6                                              'Shipper Addr2
    TransactionBuilder strTrans, 7, g_str7                                              'Shipper City
    TransactionBuilder strTrans, 8, g_str8                                              'Shipper State
    TransactionBuilder strTrans, 9, g_str9                                              'Shipper Zip
    TransactionBuilder strTrans, 117, g_str117                                          'Shipper Country
    TransactionBuilder strTrans, 183, g_str183                                          'Shipper Phone
    TransactionBuilder strTrans, 1670, RemoveSpecial(ImpliedDecimal(g_str1670))         'Weight
    
    ' 2008-09-28, JFW
    TransactionBuilder strTrans, 75, g_str75                            'Weight type
    
    TransactionBuilder strTrans, 1274, g_str1274                                        'Service Type
    TransactionBuilder strTrans, 1273, g_str1273                                        'Packaging Type
    If IsDate(g_str24) Then
        TransactionBuilder strTrans, 24, Format(g_str24, "YYYYMMDD")                    'Ship Date Note yyyymmdd format, no punctuation
    Else
        TransactionBuilder strTrans, 24, g_str24                                        'Ship Date Note yyyymmdd format, no punctuation
    End If
    TransactionBuilder strTrans, 68, g_str68                                            'Currency Type
    TransactionBuilder strTrans, 1090, g_str1090                                        'Rate Currency
    TransactionBuilder strTrans, 23, g_str23                                            'Pay Type
    TransactionBuilder strTrans, 20, g_str20                                            'Bill-To Acct#
    TransactionBuilder strTrans, 25, g_str25                                            'References
    TransactionBuilder strTrans, 3056, g_str3056                                        'P.O. Number
    TransactionBuilder strTrans, 3057, g_str3057                                        'Invoice Number
    TransactionBuilder strTrans, 38, g_str38                                            'Department Notes
    TransactionBuilder strTrans, 57, g_str57                        'DIM H
    TransactionBuilder strTrans, 58, g_str58                        'DIM W
    TransactionBuilder strTrans, 59, g_str59                        'DIM L
    'Special Svcs
    If g_str1332 = "Y" Then
        TransactionBuilder strTrans, 1332, g_str1332                                    'Alcohol Flag
        TransactionBuilder strTrans, 40, g_str40                                        'Alcohol Contents
        TransactionBuilder strTrans, 41, g_str41                                        'Alcohol Packaging
        TransactionBuilder strTrans, 42, RemoveSpecial(ImpliedDecimal(g_str42, 3))      'Alcohol Volume
        TransactionBuilder strTrans, 52, g_str52                                        'Alcohol Quantity
    End If
    'Added 8/6 And g_blnCODFirstPiece for MPS Ground COD 1st Piece
    If g_str27 = "Y" Then
        If g_str3014 = "Y" And g_str1274 = "92" Then
            TransactionBuilder strTrans, 3014, g_str3014            'ECOD Flag
        Else
            TransactionBuilder strTrans, 27, g_str27                'COD Flag
        End If
        TransactionBuilder strTrans, 53, RemoveSpecial(ImpliedDecimal(g_str53))                    'COD Amount
        If g_str1274 <> "92" Then
            TransactionBuilder strTrans, 54, g_str54                'COD Cashier Chk or MO
        Else
            TransactionBuilder strTrans, 3000, g_str3000            'COD Ground payment type
        End If
        TransactionBuilder strTrans, 186, g_str186                  'COD Add Freight Chgs
        TransactionBuilder strTrans, 439, g_str439                  'COD Remit Payer
        TransactionBuilder strTrans, 1237, g_str1237                'COD Return Phone
        TransactionBuilder strTrans, 1238, g_str1238                'COD Return Company
        TransactionBuilder strTrans, 1240, g_str1240                'COD Return Addr1
        TransactionBuilder strTrans, 1241, g_str1241                'COD Return Addr2
        TransactionBuilder strTrans, 1242, g_str1242                'COD Return City
        TransactionBuilder strTrans, 1243, g_str1243                'COD Return State
        TransactionBuilder strTrans, 1244, g_str1244                'COD Return Zip
    End If
    If g_str1268 = "Y" Then
        TransactionBuilder strTrans, 1268, g_str1268                                    'Dry Ice Flag
        TransactionBuilder strTrans, 1684, RemoveSpecial(ImpliedDecimal(g_str1684))     'Dry Ice Wgt
    End If
    If g_str1200 = "Y" Then                                         'HAL
        TransactionBuilder strTrans, 1200, g_str1200                'HAL Flag
        TransactionBuilder strTrans, 44, g_str44                    'HAL Station Address
        TransactionBuilder strTrans, 46, g_str46                    'HAL City
        TransactionBuilder strTrans, 47, g_str47                    'HAL State
        TransactionBuilder strTrans, 48, g_str48                    'HAL Postal Code
        TransactionBuilder strTrans, 49, g_str49                    'HAL Phone Number
    End If
    If g_str1274 = "90" Or g_str1274 = "92" Then
        TransactionBuilder strTrans, 3018, g_str3018                'Non-Standard Packaging
    End If
    If g_str1266 = "Y" Then
        TransactionBuilder strTrans, 1266, g_str1266                'Sat Del
    End If
    If g_str1274 = "90" Then
        TransactionBuilder strTrans, 3020, g_str3020                'FHD Special Svcs
        TransactionBuilder strTrans, 3023, g_str3023                'FHD Special Svcs
        TransactionBuilder strTrans, 3024, g_str3024                'FHD Special Svcs
    End If
    'Add Email addresses only if Email Alerts checkbox checked
    If frmShip.chkEmailAlert = 1 Then
        TransactionBuilder strTrans, 1201, g_str1201                'Shipper Email Address
        TransactionBuilder strTrans, 1553, g_str1553                'Shipper Delivery Notification Flag"
        TransactionBuilder strTrans, 1554, g_str1554                'Shipper Ship Alert Flag"
        TransactionBuilder strTrans, 1961, g_str1961                'Shipper Exception Notification Flag"
        TransactionBuilder strTrans, 1965, g_str1965                'Shipper Email Format
        
        TransactionBuilder strTrans, 1202, g_str1202                'Recipient Email Address
        TransactionBuilder strTrans, 1556, g_str1556                'Recipient Delivery Notification Flag"
        TransactionBuilder strTrans, 1557, g_str1557                'Recipient Ship Alert Flag"
        TransactionBuilder strTrans, 1962, g_str1962                'Recipient Exception Notification Flag"
        TransactionBuilder strTrans, 1967, g_str1967                'Recipient Email Format
        
        TransactionBuilder strTrans, "1204-1", g_str1204_1          'Other Email Address 1
        TransactionBuilder strTrans, "1204-2", g_str1204_2          'Other Email Address 2
        TransactionBuilder strTrans, "1204-3", g_str1204_3          'Other Email Address 3
        TransactionBuilder strTrans, "1206-1", g_str1206_1          'Other Ship Alert Flag 1
        TransactionBuilder strTrans, "1206-2", g_str1206_2          'Other Ship Alert Flag 2
        TransactionBuilder strTrans, "1206-3", g_str1206_3          'Other Ship Alert Flag 3
        TransactionBuilder strTrans, "1551-1", g_str1551_1          'Other Delivery Notification Flag 1
        TransactionBuilder strTrans, "1551-2", g_str1551_2          'Other Delivery Notification Flag 2"
        TransactionBuilder strTrans, "1551-3", g_str1551_3          'Other Delivery Notification Flag 3"
        TransactionBuilder strTrans, "1960-1", g_str1960_1          'Other Exception Notification Flag 1
        TransactionBuilder strTrans, "1960-2", g_str1960_2          'Other Exception Notification Flag 2"
        TransactionBuilder strTrans, "1960-3", g_str1960_3          'Other Exception Notification Flag 3"
        TransactionBuilder strTrans, "1964-1", g_str1964_1          'Other Email Format 1
        TransactionBuilder strTrans, "1964-2", g_str1964_2          'Other Email Format 2"
        TransactionBuilder strTrans, "1964-3", g_str1964_3          'Other Email Format 3"
        
        TransactionBuilder strTrans, 1203, g_str1203                'Email Message
        TransactionBuilder strTrans, 1555, g_str1555                'Shipper Language Code"
        TransactionBuilder strTrans, 1558, g_str1558                'Recipient Language Code"
        TransactionBuilder strTrans, "1552-1", g_str1552_1          'Other Language Code 1"
        TransactionBuilder strTrans, "1552-2", g_str1552_2          'Other Language Code 2"
        TransactionBuilder strTrans, "1552-3", g_str1552_3          'Other Language Code 3"
    End If
    
    '20071022-01 Modified this code for ADG/IDG/Haz
    With frmShip
        If .f1331(0) = 1 Or .f1331(2) = 1 Or .f1331(3) = 1 Or .f1331(4) = 1 Then
            If g_str1331 = "A" Then                 'A - ADG
                strTrans = BuildADGFlds(strTrans)
            ElseIf g_str1331 = "I" Then             'I - IDG
                strTrans = BuildIDGFlds(strTrans)
            End If
        ElseIf .f1331(1) And g_str1274 = "92" Then  'Only add Haz fields if Ground is the service.
            strTrans = BuildHazMatFlds(strTrans)
        End If
    End With
    
    TransactionBuilder strTrans, 187, g_str187                          'Label Type
    TransactionBuilder strTrans, 1660, g_str1660                        'Custom label flag
    TransactionBuilder strTrans, 537, g_str537                          'Thermal/Laser Label prt UNC/File Path
    
    '12/19/05 Added Label orientation
    TransactionBuilder strTrans, 1370, g_str1370                        'Label orientation
    
    'Don't send field 1282 if label type is laser (DIB) or PNG
    If g_str187 <> "DIB" And g_str187 <> "PNG" Then
        TransactionBuilder strTrans, 1282, g_str1282                    'Printer Type Indicator
    End If
    
    ' MsgBox 10 & " " & g_str10 & " " & 498 & " " & g_str498, vbApplicationModal
    
    ' 2010-09-21, JFW, CMA problem transacting with account, not good for Client database
    If g_str10 = "" Or g_str498 = "" Then
        Err.Raise 12345, "Account", "Account (" & g_str10 & ") or meter (" & g_str498 & ") is not set.  Location " & ""
    End If
    
    TransactionBuilder strTrans, 10, g_str10                            'Acct Number
    TransactionBuilder strTrans, 498, g_str498
    
    'Add handling charge fields for use with doc-tab
    With frmSetup
        If .chkAddHndlChg = 1 Then
            If .f1588(1) Then
                TransactionBuilder strTrans, 1588, "1"                  'Handling charge Type - flat amount
            ElseIf .f1588(2) Then
                TransactionBuilder strTrans, 1588, "2"                  'Handling charge Type - % of freight chg
            ElseIf .f1588(3) Then
                TransactionBuilder strTrans, 1588, "3"                  'Handling charge Type - % of Net chg
            End If
            'Handling chg application point
            If .f1606(0) Then
                TransactionBuilder strTrans, 1606, "0"                  'Apply to pkg
            ElseIf .f1606(1) Then
                TransactionBuilder strTrans, 1606, "1"                  'Apply to shipment
            End If
            
            If .chkBySvc = 0 Then
                TransactionBuilder strTrans, 1595, RemoveSpecial(ImpliedDecimal(.f1595(1)))            'All services have same handling chg
            Else
                Select Case g_str1274
                    Case "01"
                        TransactionBuilder strTrans, 1595, RemoveSpecial(.f1595(1))        'PO amount
                    Case "05"
                        TransactionBuilder strTrans, 1595, RemoveSpecial(.f1595(2))        'SO amount
                    Case "03"
                        TransactionBuilder strTrans, 1595, RemoveSpecial(.f1595(3))        'ES amount
                    Case "20"
                        TransactionBuilder strTrans, 1595, RemoveSpecial(.f1595(4))        'XS amount
                    Case "92"
                        TransactionBuilder strTrans, 1595, RemoveSpecial(.f1595(5))        'GR amount
                    Case "90"
                        TransactionBuilder strTrans, 1595, RemoveSpecial(.f1595(6))        'HD amount
                End Select
            End If
        End If
    End With
    
    'Added 6/16/05 Signature Required
    TransactionBuilder strTrans, 1208, g_str1208            'Signature Required flag
    If g_str1208 = "Y" Then
        TransactionBuilder strTrans, 2399, g_str2399        'Signature Required type
    End If
    
    'Alt Return Addr fields ***Updated 3/30/05 to not send for IPD shipments
    If g_str1586 = "Y" And (frmShip.chkIPD.Value = 0 And frmShip.chkIntlIPD.Value = 0) Then
        TransactionBuilder strTrans, 1586, g_str1586        'Print Alt Return flag
        TransactionBuilder strTrans, 1485, g_str1485        'Alt Return Contact
        TransactionBuilder strTrans, 1486, g_str1486        'Alt Return Company
        TransactionBuilder strTrans, 1487, g_str1487        'Alt Return Addr1
        TransactionBuilder strTrans, 1488, g_str1488        'Alt Return Addr2
        TransactionBuilder strTrans, 1489, g_str1489        'Alt Return City
        TransactionBuilder strTrans, 1490, g_str1490        'Alt Return State
        TransactionBuilder strTrans, 1491, g_str1491        'Alt Return Zip
        TransactionBuilder strTrans, 1492, g_str1492        'Alt Return Phone
        TransactionBuilder strTrans, 1585, g_str1585        'Alt Return Country
    End If
    
    'Add custom doc-tab fields
    TransactionBuilder strTrans, 581, g_str581              'Custom Doc-Tab1
    TransactionBuilder strTrans, 582, g_str582              'Custom Doc-Tab2
    TransactionBuilder strTrans, 583, g_str583              'Custom Doc-Tab3
    TransactionBuilder strTrans, 584, g_str584              'Custom Doc-Tab4
    TransactionBuilder strTrans, 585, g_str585              'Custom Doc-Tab5
    TransactionBuilder strTrans, 586, g_str586              'Custom Doc-Tab6
    TransactionBuilder strTrans, 587, g_str587              'Custom Doc-Tab7
    TransactionBuilder strTrans, 588, g_str588              'Custom Doc-Tab8
    TransactionBuilder strTrans, 589, g_str589              'Custom Doc-Tab9
    TransactionBuilder strTrans, 590, g_str590              'Custom Doc-Tab10
    TransactionBuilder strTrans, 591, g_str591              'Custom Doc-Tab11
    TransactionBuilder strTrans, 592, g_str592              'Custom Doc-Tab12
    
    '01/20/06 Added for Intra-CA Sig Rel
    If g_str51 = "Y" Then
        TransactionBuilder strTrans, 51, g_str51            'Sig Rel Flag
        TransactionBuilder strTrans, 1118, g_str1118        'Sig Rel #
    End If
    
    BuildCommonFlds = strTrans

    Exit Function
EH:
     MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildCommonFlds"

End Function
'---------------------------------------------------------------------------------------
' Module    : BuildDomShipTrans
' DateTime  : 1/11/2006
' Author    : Chris Elwell
' Purpose   : Builds and returns the transaction string for LTL BOL shipments
'---------------------------------------------------------------------------------------
'
Public Function BuildLTLBOLTrans() As String
    
    Dim strTrans As String
    Dim rsLTL As New ADODB.Recordset
    Dim strQuery As String
    Dim i As Integer
    
    On Error GoTo EH
    
    'Build the FXRS transaction
    strTrans = ""
    TransactionBuilder strTrans, 0, "020"                            'Transaction type
    TransactionBuilder strTrans, 1, g_str1                           'Transaction ID
    TransactionBuilder strTrans, 50, g_str50                         'Country - 2 character code
    TransactionBuilder strTrans, 12, g_str12                         'Recipient Contact
    TransactionBuilder strTrans, 11, g_str11                         'Recipient Company Name
    TransactionBuilder strTrans, 13, g_str13                         'Recipient Addr1
    TransactionBuilder strTrans, 14, g_str14                         'Recipient Addr2
    TransactionBuilder strTrans, 15, g_str15                         'Recipient City
    TransactionBuilder strTrans, 16, g_str16                         'Recipient State
    TransactionBuilder strTrans, 17, g_str17                         'Recipient Zip
    TransactionBuilder strTrans, 18, g_str18                         'Phone - Using shipper phone
    TransactionBuilder strTrans, 4, g_str4                           'Shipper Company Name
    TransactionBuilder strTrans, 5, g_str5                           'Shipper Addr1
    TransactionBuilder strTrans, 6, g_str6                           'Shipper Addr2
    TransactionBuilder strTrans, 7, g_str7                           'Shipper City
    TransactionBuilder strTrans, 8, g_str8                           'Shipper State
    TransactionBuilder strTrans, 9, g_str9                           'Shipper Zip
    TransactionBuilder strTrans, 117, g_str117                       'Shipper Country
    TransactionBuilder strTrans, 183, g_str183                       'Shipper Phone
    TransactionBuilder strTrans, 69, RemoveSpecial(ImpliedDecimal(g_str69))                         'Shipper Contact Name
    If IsDate(g_str24) Then
        TransactionBuilder strTrans, 24, Format(g_str24, "YYYYMMDD")                    'Ship Date Note yyyymmdd format, no punctuation
    Else
        TransactionBuilder strTrans, 24, g_str24                                        'Ship Date Note yyyymmdd format, no punctuation
    End If
    TransactionBuilder strTrans, 6100, "Y"                          'LTL Flag
    TransactionBuilder strTrans, 1222, g_str1222                    'ProNumber
    TransactionBuilder strTrans, 6110, g_str6110                    'LTL Spcl Svcs
    TransactionBuilder strTrans, 6107, g_str6107                    'Shipment terms
    TransactionBuilder strTrans, 6108, g_str6108                    'Shipper #1
    TransactionBuilder strTrans, 6109, g_str6109                    'Shipper #2
    TransactionBuilder strTrans, 3021, g_str3021                    'Spcl Instr
    TransactionBuilder strTrans, 484, g_str484                      'Haz-Mat Phone#
    TransactionBuilder strTrans, 23, g_str23                        'Payment Type
    '20070605-01 Added Inside P/U and Del
    TransactionBuilder strTrans, 1120, g_str1120                    'Inside P/U
    TransactionBuilder strTrans, 1121, g_str1121                    'Inside Del
    If g_str23 = "3" Then
        TransactionBuilder strTrans, 4647, g_str4647                'Payor Company
        TransactionBuilder strTrans, 4639, g_str4639                'Payor Addr1
        TransactionBuilder strTrans, 6102, g_str6102                'Payor P.O. Box
        TransactionBuilder strTrans, 4641, g_str4641                'Payor City
        TransactionBuilder strTrans, 4648, g_str4648                'Payor Zip
        TransactionBuilder strTrans, 4649, g_str4649                'Payor State
    End If
    If g_str27 = "Y" Then
        TransactionBuilder strTrans, 27, g_str27                    'COD Flag
        TransactionBuilder strTrans, 53, RemoveSpecial(ImpliedDecimal(g_str53)) 'COD Amount
        TransactionBuilder strTrans, 3000, g_str3000                'COD Ground payment type
        TransactionBuilder strTrans, 6103, g_str6103                'COD Remit Payor
        TransactionBuilder strTrans, 6104, g_str6104                'COD Fee Payor
        TransactionBuilder strTrans, 439, g_str439                  'COD Remit Payer
        TransactionBuilder strTrans, 1237, g_str1237                'COD Return Phone
        TransactionBuilder strTrans, 1238, g_str1238                'COD Return Company
        TransactionBuilder strTrans, 1240, g_str1240                'COD Return Addr1
        TransactionBuilder strTrans, 1241, g_str1241                'COD Return Addr2
        TransactionBuilder strTrans, 1242, g_str1242                'COD Return City
        TransactionBuilder strTrans, 1243, g_str1243                'COD Return State
        TransactionBuilder strTrans, 1244, g_str1244                'COD Return Zip
    End If
    
    strQuery = "SELECT * FROM LTLMulti WHERE f1 = " & SingleQuotes(g_str1)
    strQuery = strQuery + " AND Workstation = '" & g_strComputerName & "'"
    
    rsLTL.Open strQuery, g_connFSMSClient, adOpenStatic, adLockBatchOptimistic
    
    i = 1
    Do Until rsLTL.EOF
        TransactionBuilder strTrans, "6105-" & Trim(Str(i)), rsLTL!f6105    'NMFC Class
        TransactionBuilder strTrans, "6106-" & Trim(Str(i)), rsLTL!f6106    'NMFC Item#
        TransactionBuilder strTrans, "1670-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(rsLTL!f1670))    'Weight
        TransactionBuilder strTrans, "57-" & Trim(Str(i)), rsLTL!f57        'DIM W
        TransactionBuilder strTrans, "58-" & Trim(Str(i)), rsLTL!f58        'DIM H
        TransactionBuilder strTrans, "59-" & Trim(Str(i)), rsLTL!f59        'DIM L
        TransactionBuilder strTrans, "2931-" & Trim(Str(i)), rsLTL!f2931    '# of Pieces
        TransactionBuilder strTrans, "1271-" & Trim(Str(i)), rsLTL!f1271    '# of Pieces
        TransactionBuilder strTrans, "1331-" & Trim(Str(i)), rsLTL!f1331    'Haz-Mat flag
        TransactionBuilder strTrans, "79-" & Trim(Str(i)), rsLTL!f79        'Desc
        TransactionBuilder strTrans, "3056-" & Trim(Str(i)), rsLTL!f3056    'PO#
        TransactionBuilder strTrans, "4683-" & Trim(Str(i)), rsLTL!f4683    'BOL#
        TransactionBuilder strTrans, "6101-" & Trim(Str(i)), rsLTL!f6101    'Volume

        i = i + 1
        rsLTL.MoveNext
    Loop
    
    ' 2008-09-28, JFW
    TransactionBuilder strTrans, 75, g_str75                            'Weight type
    
    TransactionBuilder strTrans, 187, g_str187                          'Label Type
    TransactionBuilder strTrans, 537, g_str537                          'Thermal/Laser Label prt UNC/File Path
    TransactionBuilder strTrans, 538, g_str538                          'Report printer
       
       '12/19/05 Added Label orientation
    TransactionBuilder strTrans, 1370, g_str1370                        'Label orientation
    'Don't send field 1282 if label type is laser (DIB) or PNG
    If g_str187 <> "DIB" And g_str187 <> "PNG" Then
        TransactionBuilder strTrans, 1282, g_str1282                    'Printer Type Indicator
    End If
    TransactionBuilder strTrans, 538, g_str538                          'Report printer
    
    TransactionBuilder strTrans, 99, ""                             'End of Transaction
    BuildLTLBOLTrans = strTrans
    
    Exit Function
EH:
     MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildDomShipTrans"

End Function
'---------------------------------------------------------------------------------------
' Module    : BuildDomShipTrans
' DateTime  : 2/18/2004
' Author    : Chris Elwell
' Purpose   : Builds and returns the transaction string for Domestic shipping
'---------------------------------------------------------------------------------------
'
Public Function BuildDomShipTrans() As String
    Dim strTrans As String

    On Error GoTo EH
    
    'Build the FXRS transaction
    strTrans = BuildCommonFlds
    '20080123-01 Added for Priority Alert
    If g_str1209 = "Y" Then
        TransactionBuilder strTrans, 1209, g_str1209                'Priority Alert Flag
        TransactionBuilder strTrans, "1337-1", g_str1337_1          'Priority Contents 1
        TransactionBuilder strTrans, "1337-2", g_str1337_2          'Priority Contents 2
    End If
    
    TransactionBuilder strTrans, 99, ""                             'End of Transaction
    
    BuildDomShipTrans = strTrans

    Exit Function
EH:
    MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildDomShipTrans"

End Function
'---------------------------------------------------------------------------------------
' Module    : BuildIntlMPSShipTrans
' DateTime  : 3/08/2004
' Modified  : 2/24/2005 - Modified code to use MPS form or main screen
' Author    : Chris Elwell
' Purpose   : Builds and returns the transaction string for MPS Intl
'---------------------------------------------------------------------------------------
'
Public Function BuildIntlMPSShipTrans(ByVal strOrderNum As String) As String
    Dim strTrans As String
    Dim strQuery As String
    Dim rsCommodity As New ADODB.Recordset
    Dim i As Integer
    Dim rsIntlMPS As New ADODB.Recordset
    Dim boolTDMPS3056 As Boolean
    Dim boolTDMPS3057 As Boolean
    
    On Error GoTo EH
    
    strQuery = "SELECT * FROM IntlCommodities WHERE f1 = '" & strOrderNum & "'"
    strQuery = strQuery & " AND Workstation = '" & g_strComputerName & "'"
    strQuery = strQuery & " AND (g_str29 IS NULL OR g_str29 = '')"
    
    rsCommodity.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    
    If CheckIntlCommodities(rsCommodity) <> "" Then
        Err.Raise 12345, "BuildIntlMPSShipTrans", CheckIntlCommodities(rsCommodity)
    End If
    
    'Build the common fields
    strTrans = BuildCommonFlds
    
    'Loop through Intl MPS
    i = 1
    
    strQuery = "SELECT * FROM MPS WHERE f1 = '" & strOrderNum & "'"
    strQuery = strQuery & " AND Workstation = '" & g_strComputerName & "'"
    strQuery = strQuery & " order by ShipDate"
    
    rsIntlMPS.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    'If using the MPS form get values from recordset
    If rsIntlMPS.RecordCount > 0 Then
        ' 2010-04-27, JFW, Express package count on TD MPS
        If frmShip.f1482.Value = True Then
            If g_str1274 <> "92" And g_str1274 <> "90" Then
                boolTDMPS3056 = True
                boolTDMPS3057 = True
                Do Until rsIntlMPS.EOF
                    If rsIntlMPS!g_str3056 & "" <> "" Then boolTDMPS3056 = False
                    If rsIntlMPS!g_str3057 & "" <> "" Then boolTDMPS3057 = False
                    rsIntlMPS.MoveNext
                Loop
                rsIntlMPS.MoveFirst
                If boolTDMPS3057 Then boolTDMPS3056 = False
            End If
        End If
        Do Until rsIntlMPS.EOF
            TransactionBuilder strTrans, "57-" & Trim(Str(i)), rsIntlMPS!g_str57 & ""            'CI Freight Charge
            TransactionBuilder strTrans, "58-" & Trim(Str(i)), rsIntlMPS!g_str58 & ""            'CI Insurance Charge
            TransactionBuilder strTrans, "59-" & Trim(Str(i)), rsIntlMPS!g_str59 & ""            'CI Other Charge
            TransactionBuilder strTrans, "1670-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(rsIntlMPS!g_str1670)) & ""
            TransactionBuilder strTrans, "26-" & Trim(Str(i)), rsIntlMPS!g_str26 & ""            'References
            TransactionBuilder strTrans, "25-" & Trim(Str(i)), rsIntlMPS!g_str25 & ""            'References
            If boolTDMPS3056 Then
                TransactionBuilder strTrans, "3056-" & Trim(Str(i)), "Pkg " & i & " of " & rsIntlMPS.RecordCount
            Else
                TransactionBuilder strTrans, "3056-" & Trim(Str(i)), rsIntlMPS!g_str3056 & ""        'P.O. #
            End If
            If boolTDMPS3057 Then
                TransactionBuilder strTrans, "3057-" & Trim(Str(i)), "Pkg " & i & " of " & rsIntlMPS.RecordCount
            Else
                TransactionBuilder strTrans, "3057-" & Trim(Str(i)), rsIntlMPS!g_str3057 & ""        'Inv #
            End If
            'Added 6/16/05 for Sig Svc options
            Select Case rsIntlMPS!g_str2399
                Case "IDR"
                    TransactionBuilder strTrans, "2399-" & Trim(Str(i)), "2"                    'Indirect Sig Req
                Case "DSR"
                    TransactionBuilder strTrans, "2399-" & Trim(Str(i)), "3"                    'Direct Sig Req
                Case "ASR"
                    TransactionBuilder strTrans, "2399-" & Trim(Str(i)), "4"                    'Adult Sig Req
            End Select
        
'            'Total Declared Value
'            g_str26 = Str(Val(g_str26) + Val(rsIntlMPS!g_str26 & ""))
            
            If rsIntlMPS("g_str3018") = 1 Then
                 TransactionBuilder strTrans, "3018-" & Trim(Str(i)), "Y"                        'Non-standard pkging
            End If

            '8/17/05 Ground COD on subsequent MPS pieces -- added by Mark Waldmann #451355
            ' 2010-04-27, JFW, For use by TD MPS
            If frmShip.f1482.Value = True Then
                If g_str1274 = "92" And g_str27 = "Y" Then
                    If frmCOD.chkCOD1stPiece = 0 Then
                        If g_str3014 = "Y" Then
                            TransactionBuilder strTrans, "3014-" & Trim(Str(i)), g_str3014           'ECOD Flag
                        Else
                            TransactionBuilder strTrans, "27-" & Trim(Str(i)), g_str27               'COD Flag
                        End If
                        TransactionBuilder strTrans, "53-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(g_str53))  'COD amount for each package in Ground shipment
                    End If
                End If
            End If
            
            i = i + 1
            rsIntlMPS.MoveNext
        Loop
'        TransactionBuilder strTrans, 26, Trim(Str(CLng(Val(g_str26))))       'Carriage Value
    'Else get values from main form
    Else
        TransactionBuilder strTrans, 116, g_str116                          '# of Pkgs
    End If
    
    ' 2008-09-28, JFW
    TransactionBuilder strTrans, 75, g_str75                            'Weight type
    
    TransactionBuilder strTrans, 1116, g_str1116            'DIM Units
    'Build the Intl MPS fields
    TransactionBuilder strTrans, 1349, g_str1349            'AES Filing Status
    TransactionBuilder strTrans, 1352, g_str1352            'Sender ID Type
    TransactionBuilder strTrans, 1139, g_str1139            'Sender IRS/EIN
    TransactionBuilder strTrans, 70, g_str70                'Duty/Tax Pay Type
    TransactionBuilder strTrans, 71, g_str71                'Duty/Tax Acct#
    TransactionBuilder strTrans, 73, g_str73                'Parties Related Flag
    TransactionBuilder strTrans, 75, g_str75                'Weight type
    'Added 3/18/05 to pass IRS/EIN for CA
    If g_str117 = "CA" Then
        TransactionBuilder strTrans, 118, g_str118          'IRS/EIN #
    Else
        TransactionBuilder strTrans, 1358, g_str1358        'FTSR Exemption #
    End If
    
    'Added 7/22/05 for Admissibility pkg type for US to CA and CA to US
    TransactionBuilder strTrans, 1958, g_str1958            'Admissibility pkg type
    
    TransactionBuilder strTrans, 413, g_str413              'NAFTA Flag
    'Loop through commodities
    i = 1
    g_str119 = "0"
    Do While Not rsCommodity.EOF
        If IsNumeric(rsCommodity!g_str77) Then
            If g_str75 = "LBS" Then
                TransactionBuilder strTrans, "77-1-" & Trim(Str(i)), RoundUp(rsCommodity!g_str77) & ""             'Commodity Weight
            Else
                TransactionBuilder strTrans, "77-1-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(rsCommodity!g_str77, 1)) & ""             'Commodity Weight
            End If
        End If
        TransactionBuilder strTrans, "78-1-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(rsCommodity!g_str78)) & ""             'Commodity Weight
        TransactionBuilder strTrans, "79-1-" & Trim(Str(i)), rsCommodity!g_str79 & ""                          'Description
        TransactionBuilder strTrans, "80-1-" & Trim(Str(i)), rsCommodity!g_str80 & ""                          'Country of Manu
        TransactionBuilder strTrans, "81-1-" & Trim(Str(i)), rsCommodity!g_str81 & ""                          'Harmonized Code
        TransactionBuilder strTrans, "82-1-" & Trim(Str(i)), rsCommodity!g_str82 & ""                          'Quantity
        TransactionBuilder strTrans, "83-1-" & Trim(Str(i)), rsCommodity!g_str83 & ""                          'Export license #
        TransactionBuilder strTrans, "84-1-" & Trim(Str(i)), Format(rsCommodity!g_str84, "YYYYMMDD") & ""      'Export license Exp Date
        TransactionBuilder strTrans, "414-1-" & Trim(Str(i)), rsCommodity!g_str414 & ""                        'Unit of Measure
        TransactionBuilder strTrans, "1030-1-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(rsCommodity!g_str1030, 6)) & ""       'Commodity Unit Value
        TransactionBuilder strTrans, "1275-1-" & Trim(Str(i)), rsCommodity!g_str1275 & ""                        'Part number
        TransactionBuilder strTrans, "120-1-" & Trim(Str(i)), rsCommodity!g_str120 & ""
        
        If IsNumeric(rsCommodity!g_str82) _
        And IsNumeric(rsCommodity!g_str1030) Then
            g_str119 = CDbl(g_str119) + CDbl(rsCommodity!g_str82) * CDbl(rsCommodity!g_str1030)
        End If
        
        i = i + 1
        rsCommodity.MoveNext
    Loop
    If g_str119 <> "" And g_str119 <> "0" Then
        TransactionBuilder strTrans, "119", g_str119
    End If
    If g_str113 = "Y" Then
        TransactionBuilder strTrans, 113, g_str113                                  'CI Flag
        TransactionBuilder strTrans, 72, g_str72                                    'Terms of Sale
        TransactionBuilder strTrans, 532, RemoveSpecial(ImpliedDecimal(g_str532))   'CI Freight Charge
        TransactionBuilder strTrans, 533, RemoveSpecial(ImpliedDecimal(g_str533))   'CI Insurance Charge
        TransactionBuilder strTrans, 534, RemoveSpecial(ImpliedDecimal(g_str534))   'CI Other Charge
        TransactionBuilder strTrans, 1357, g_str1357                                'CI Other Chg Type
        TransactionBuilder strTrans, "418-1", g_str418_1                            'CI Comment 1
        TransactionBuilder strTrans, "418-2", g_str418_2                            'CI Comment 2
        TransactionBuilder strTrans, "418-3", g_str418_3                            'CI Comment 3
        TransactionBuilder strTrans, 538, g_str538                                  'CI Printer UNC
    Else
        TransactionBuilder strTrans, 113, "N"                                       'CI Flag
    End If
    
    ' 2011-04-08, JFW, ETD
    If g_strETD <> "" Then
        strTrans = strTrans & g_strETD
    Else
        TransactionBuilder strTrans, 2805, "N"
        TransactionBuilder strTrans, 1688, "3"
        TransactionBuilder strTrans, 2103, "3"
    End If
    
    If g_str1174 = "Y" Then
        TransactionBuilder strTrans, 1174, g_str1174        'BSO Flag
        TransactionBuilder strTrans, 66, g_str66            'Broker Name
        TransactionBuilder strTrans, 67, g_str67            'Broker Phone
        TransactionBuilder strTrans, 1179, g_str1179        'Broker Acct#
        TransactionBuilder strTrans, 1180, g_str1180        'Broker Company
        TransactionBuilder strTrans, 1181, g_str1181        'Broker Addr1
        TransactionBuilder strTrans, 1182, g_str1182        'Broker Addr2
        TransactionBuilder strTrans, 1183, g_str1183        'Broker City
        TransactionBuilder strTrans, 1184, g_str1184        'Broker St/Prov
        TransactionBuilder strTrans, 1185, g_str1185        'Broker POstal Code
        TransactionBuilder strTrans, 1186, g_str1186        'Broker Country
        TransactionBuilder strTrans, 1187, g_str1187        'Broker ID
        TransactionBuilder strTrans, 1343, g_str1343        'Broker Email
        TransactionBuilder strTrans, 1344, g_str1344        'Broker Fax#
        TransactionBuilder strTrans, 1345, g_str1345        'Broker Pager #
    End If
    
    'Added 3/3/05 for CA Export
    If g_str117 = "CA" Then
        If frmShip.chkB13A = 1 Then
            TransactionBuilder strTrans, 1651, g_str1651        'B13A Filing Options
            TransactionBuilder strTrans, 1652, g_str1652        'Export Statement Data
            TransactionBuilder strTrans, 1653, g_str1653        'Export Permit #
        Else
            TransactionBuilder strTrans, 1651, "1"              'B13A Filing Options
        End If
    End If
    
    ' 2007-05-14, JFW, FXRS 840
    If frmShip.f1482.Value = 1 Then
        ' 2007-05-15, JFW, TDChild
        g_blnTDChild = True
        ' g_blnTD = True
        TransactionBuilder strTrans, 541, "NNNYNNNNN"                               'Open Ship Flags
        TransactionBuilder strTrans, 542, g_strTDOpenShip
    End If
    
    TransactionBuilder strTrans, 99, ""                             'End of Transaction
    
    BuildIntlMPSShipTrans = strTrans

Release:
    If rsCommodity.State = adStateOpen Then rsCommodity.Close
    Set rsCommodity = Nothing
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildIntlMPSShipTrans"
    Resume Release
    If False Then
        Resume
    End If
    
End Function
'---------------------------------------------------------------------------------------
' Module    : BuildDomMPSShipTrans
' DateTime  : 3/18/2004
' Modified  : 8/6/2004, 2/8/2005
' Author    : Chris Elwell
' Purpose   : Builds and returns the transaction string for Ground MPS
'             8/6/2004 added to code for MPS COD on First Piece
'             2/8/2005 changed DV to multiple occurrence fields
'---------------------------------------------------------------------------------------
'
Public Function BuildDomMPSShipTrans(ByVal strOrderNum As String) As String
    Dim strTrans As String
    Dim strQuery As String
    Dim rsDomMPS As New ADODB.Recordset
    Dim i As Integer
    
    On Error GoTo EH
    
    strQuery = "SELECT * FROM MPS WHERE f1 = '" & strOrderNum & "'"
    strQuery = strQuery & " AND Workstation = '" & g_strComputerName & "'"
    strQuery = strQuery & " order by ShipDate"
    
    rsDomMPS.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    
    'Build the common fields
    strTrans = BuildCommonFlds
    
    'Loop through Dom MPS fields
    i = 1
    Do While Not rsDomMPS.EOF
        
        TransactionBuilder strTrans, "1670-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(rsDomMPS("g_str1670")))
        TransactionBuilder strTrans, "26-" & Trim(Str(i)), rsDomMPS!g_str26 & ""        'Declared Value
        TransactionBuilder strTrans, "57-" & Trim(Str(i)), rsDomMPS!g_str57 & ""        'DIM H
        TransactionBuilder strTrans, "58-" & Trim(Str(i)), rsDomMPS!g_str58 & ""        'DIM W
        TransactionBuilder strTrans, "59-" & Trim(Str(i)), rsDomMPS!g_str59 & ""        'DIM L
        TransactionBuilder strTrans, "25-" & Trim(Str(i)), rsDomMPS!g_str25 & ""        'References
        TransactionBuilder strTrans, "3056-" & Trim(Str(i)), rsDomMPS!g_str3056 & ""    'P.O. #
        TransactionBuilder strTrans, "3057-" & Trim(Str(i)), rsDomMPS!g_str3057 & ""    'Inv #
        'Added 6/16/05 for Sig Svc options
        Select Case rsDomMPS("g_str2399")
            Case "IDR"
                TransactionBuilder strTrans, "2399-" & Trim(Str(i)), "2"                    'Indirect Sig Req
            Case "DSR"
                TransactionBuilder strTrans, "2399-" & Trim(Str(i)), "3"                    'Direct Sig Req
            Case "ASR"
                TransactionBuilder strTrans, "2399-" & Trim(Str(i)), "4"                    'Adult Sig Req
        End Select
        
        If rsDomMPS("g_str3018") = 1 Then
            TransactionBuilder strTrans, "3018-" & Trim(Str(i)), "Y"                        'Non-standard pkging
        End If
        
        i = i + 1
        rsDomMPS.MoveNext
        
        '8/17/05 Ground COD on subsequent MPS pieces -- added by Mark Waldmann #451355
        If g_str1274 = "92" And frmCOD.chkCOD1stPiece = 0 And frmShip.f27(2) = 1 Then
            If g_str3014 = "Y" Then
                TransactionBuilder strTrans, "3014-" & Trim(Str(i)), g_str3014           'ECOD Flag
            Else
                TransactionBuilder strTrans, "27-" & Trim(Str(i)), g_str27               'COD Flag
            End If
            TransactionBuilder strTrans, "53-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(g_str53))  'COD amount for each package in Ground shipment
        End If
    
    Loop
    
    ' 2008-09-28, JFW
    TransactionBuilder strTrans, 75, g_str75                            'Weight type
    
    'Add end of transaction string
    TransactionBuilder strTrans, 99, ""                                                     'End of Transaction
    
    'Return transaction string
    BuildDomMPSShipTrans = strTrans
    
Release:
    If rsDomMPS.State = adStateOpen Then
        rsDomMPS.Close
    End If
    Set rsDomMPS = Nothing
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildDomMPSShipTrans"
    Resume Release

End Function
'---------------------------------------------------------------------------------------
' Module    : BuildIntlDocShipTrans
' DateTime  : 3/18/2004
' Modified  : 3/27/2006 Added MPS capability
' Author    : Chris Elwell
' Purpose   : Builds and returns the transaction string for Intl documents
'---------------------------------------------------------------------------------------
'
Public Function BuildIntlDocShipTrans(ByVal str1 As String) As String
    On Error GoTo EH
    
    Dim strTrans As String
    Dim strQuery As String
    Dim i As Integer
    Dim rsIntlMPS As New ADODB.Recordset
    
    'Build the common fields
    strTrans = BuildCommonFlds
    
    'Loop through Intl MPS
    i = 1
    
    strQuery = "SELECT * FROM MPS WHERE f1 = '" & str1 & "'"
    strQuery = strQuery & " AND Workstation = '" & g_strComputerName & "'"
    strQuery = strQuery & " order by ShipDate"
    
    rsIntlMPS.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    'If using the MPS form get values from recordset
    If rsIntlMPS.RecordCount > 0 Then
        Do Until rsIntlMPS.EOF
            TransactionBuilder strTrans, "57-" & Trim(Str(i)), rsIntlMPS("g_str57") & ""            'CI Freight Charge
            TransactionBuilder strTrans, "58-" & Trim(Str(i)), rsIntlMPS("g_str58") & ""            'CI Insurance Charge
            TransactionBuilder strTrans, "59-" & Trim(Str(i)), rsIntlMPS("g_str59") & ""            'CI Other Charge
            TransactionBuilder strTrans, "1670-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(rsIntlMPS("g_str1670"))) & ""
            TransactionBuilder strTrans, "25-" & Trim(Str(i)), rsIntlMPS("g_str25") & ""            'References
            TransactionBuilder strTrans, "3056-" & Trim(Str(i)), rsIntlMPS("g_str3056") & ""        'P.O. #
            TransactionBuilder strTrans, "3057-" & Trim(Str(i)), rsIntlMPS("g_str3057") & ""        'Inv #
            'Added 6/16/05 for Sig Svc options
            Select Case rsIntlMPS("g_str2399")
                Case "IDR"
                    TransactionBuilder strTrans, "2399-" & Trim(Str(i)), "2"                    'Indirect Sig Req
                Case "DSR"
                    TransactionBuilder strTrans, "2399-" & Trim(Str(i)), "3"                    'Direct Sig Req
                Case "ASR"
                    TransactionBuilder strTrans, "2399-" & Trim(Str(i)), "4"                    'Adult Sig Req
            End Select
        
            If rsIntlMPS("g_str3018") = 1 Then
                 TransactionBuilder strTrans, "3018-" & Trim(Str(i)), "Y"                        'Non-standard pkging
            End If
            i = i + 1
            rsIntlMPS.MoveNext
        Loop
    'Else get values from main form
    Else
        TransactionBuilder strTrans, 116, g_str116                          '# of Pkgs
    End If
    
    TransactionBuilder strTrans, 75, g_str75                'Weight type
    TransactionBuilder strTrans, 79, g_str79                'Description
    TransactionBuilder strTrans, 80, g_str80                'Country of Manufacture
    'Set Doc Customs Value = to value in f26 X 100
    TransactionBuilder strTrans, 119, Trim(Str(Val(g_str26) * 100))      'Customs Value
    TransactionBuilder strTrans, 1349, g_str1349            'AES Filing Status
    TransactionBuilder strTrans, 1352, g_str1352            'Sender ID Type
    TransactionBuilder strTrans, 1139, g_str1139            'Sender IRS/EIN
    'Added 7/22/05 for Admissibility pkg type for US to CA and CA to US
    TransactionBuilder strTrans, 1958, g_str1958            'Admissibility pkg type
    '03/27/06 Added Intl doc flag
    TransactionBuilder strTrans, 190, g_str190              'Intl Doc Flag
    TransactionBuilder strTrans, 99, ""                     'End of Transaction

    BuildIntlDocShipTrans = strTrans
    
    Exit Function
EH:
     MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildIntlDocShipTrans"
    
End Function
'---------------------------------------------------------------------------------------
' Module    : BuildCADomShipTrans
' DateTime  : 1/27/2005
' Author    : Chris Elwell
' Purpose   : Builds and returns the transaction string for Intra-CA shipping
'---------------------------------------------------------------------------------------
'
Public Function BuildCADomShipTrans() As String
    Dim strTrans As String

    On Error GoTo EH
    
    ' Interaction.MsgBox "BuildCADomShipTrans", vbApplicationModal
    
    'Build the FXRS transaction
    strTrans = BuildCommonFlds
    TransactionBuilder strTrans, 116, g_str116                      '# pkgs
    TransactionBuilder strTrans, 75, g_str75                        'wgt type
    TransactionBuilder strTrans, 26, Trim(Str(CLng(Val(g_str26))))               'Declared Value
    TransactionBuilder strTrans, 57, g_str57                        'DIM H
    TransactionBuilder strTrans, 58, g_str58                        'DIM W
    TransactionBuilder strTrans, 59, g_str59                        'DIM L
    TransactionBuilder strTrans, 99, ""                             'End of Transaction
    
    BuildCADomShipTrans = strTrans

    Exit Function
EH:
    MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildCADomShipTrans"

End Function
'---------------------------------------------------------------------------------------
' Module    : BuildReturnLabel
' DateTime  : 7/26/2004
' Modified  : 4/27/2006 Added DIM fields
' Author    : Chris Elwell
' Purpose   : Builds and returns the fields required for a Ground Return Label.
'---------------------------------------------------------------------------------------
'
Public Function BuildReturnLabel() As String
    Dim strTrans As String

    On Error GoTo EH
    
    DebugPrint "BuildReturnLabel from " & g_str11 & " to " & g_str4Return
    
    'Build the FXRS transaction *** REVERSE SHIPPER AND RECIPIENT FIELDS
    strTrans = ""
    TransactionBuilder strTrans, 0, "020"                           'Transaction type
    TransactionBuilder strTrans, 1, "RETURN"                        'Transaction ID
    TransactionBuilder strTrans, 117, g_str50                       'Country - 2 character code
    TransactionBuilder strTrans, 32, g_str12                        'Recipient Contact
    TransactionBuilder strTrans, 4, g_str11                         'Recipient Company Name
    TransactionBuilder strTrans, 5, g_str13                         'Recipient Addr1
    TransactionBuilder strTrans, 6, g_str14                         'Recipient Addr2
    TransactionBuilder strTrans, 7, g_str15                         'Recipient City
    TransactionBuilder strTrans, 8, g_str16                         'Recipient State
    TransactionBuilder strTrans, 9, g_str17                         'Recipient Zip
    TransactionBuilder strTrans, 183, g_str18                       'Recipient Phone
    TransactionBuilder strTrans, 12, g_str32Return                  'Return Contact Name
    TransactionBuilder strTrans, 11, g_str4Return                   'Return Company Name
    TransactionBuilder strTrans, 13, g_str5Return                   'Return Addr1
    TransactionBuilder strTrans, 14, g_str6Return                   'Return Addr2
    TransactionBuilder strTrans, 15, g_str7Return                   'Return City
    TransactionBuilder strTrans, 16, g_str8Return                   'Return State
    TransactionBuilder strTrans, 17, g_str9Return                   'Return Zip
    TransactionBuilder strTrans, 50, g_str117Return                 'Return Country
    TransactionBuilder strTrans, 18, g_str183Return                 'Return Phone
    TransactionBuilder strTrans, 23, g_str23                                            'Pay Type
    TransactionBuilder strTrans, 20, g_str20                                            'Bill-To Acct#
    TransactionBuilder strTrans, 1670, RemoveSpecial(ImpliedDecimal(g_str1670))         'Weight                              'Weight
    
    ' 2008-09-28, JFW
    TransactionBuilder strTrans, 75, g_str75                            'Weight type
    
    TransactionBuilder strTrans, 1274, g_str1274Return                                  'Service Type
    TransactionBuilder strTrans, 1273, g_str1273Return                                  'Packaging Type
    TransactionBuilder strTrans, 1958, g_str1958                    'Admissibility Pkg Type
    TransactionBuilder strTrans, 25, g_str25                                            'References
    TransactionBuilder strTrans, 3056, g_str3056                                        'P.O. Number
    TransactionBuilder strTrans, 3057, g_str3057                                        'Invoice Number
    TransactionBuilder strTrans, 2210, g_str2210                                        'RMA Number
    TransactionBuilder strTrans, 38, g_str38                                            'Department Notes
    TransactionBuilder strTrans, 537, g_str537                          'Thermal Label prt UNC/File Path
    If g_str1282 <> "L" Then
        TransactionBuilder strTrans, 187, g_str187                      'Thermal Label Type
    End If
    'Don't send field 1282 if label type is laser (DIB) or PNG
    If g_str187 <> "DIB" And g_str187 <> "PNG" Then
        TransactionBuilder strTrans, 1282, g_str1282                    'Printer Type Indicator
    End If
    
    TransactionBuilder strTrans, 10, g_str10                            'Acct Number
    TransactionBuilder strTrans, 2382, "2"                              'Create Return label
    
    '20070615-01 Added Label orientation flag
    TransactionBuilder strTrans, 1370, g_str1370                        'Label orientation
    TransactionBuilder strTrans, 57, g_str57                            'DIM H
    TransactionBuilder strTrans, 58, g_str58                            'DIM W
    TransactionBuilder strTrans, 59, g_str59                            'DIM L
    
    TransactionBuilder strTrans, 5542, "5"
    
    TransactionBuilder strTrans, 99, ""                                 'End of Transaction
    
    BuildReturnLabel = strTrans

    DebugPrint "BuildReturnLabel done " & g_str11 & " to " & g_str4Return

    Exit Function
EH:
     MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildReturnLabel"

End Function
'---------------------------------------------------------------------------------------
' Module    : BuildOnlineReturnLabel
' DateTime  : 6/24/2005
' Modified  : 4/27/2006 Added DIM fields
' Author    : Chris Elwell
' Purpose   : Builds and returns the fields required for a Ground Return Label.
'---------------------------------------------------------------------------------------
'
Public Function BuildOnlineReturnLabel() As String
    Dim strTrans As String

    On Error GoTo EH
    
    'Build the FXRS transaction *** REVERSE SHIPPER AND RECIPIENT FIELDS
    strTrans = ""
    TransactionBuilder strTrans, 0, "037"                           'Transaction type
    ' 2014-10-16, JFW, Tag 1 should be return.
    ' TransactionBuilder strTrans, 1, g_str1                          'Transaction ID
    TransactionBuilder strTrans, 1, "RETURN"                        'Transaction ID
    TransactionBuilder strTrans, 117, g_str50                        'Country - 2 character code
    TransactionBuilder strTrans, 32, g_str12                        'Recipient Contact
    TransactionBuilder strTrans, 4, g_str11                         'Recipient Company Name
    TransactionBuilder strTrans, 5, g_str13                         'Recipient Addr1
    TransactionBuilder strTrans, 6, g_str14                         'Recipient Addr2
    TransactionBuilder strTrans, 7, g_str15                         'Recipient City
    TransactionBuilder strTrans, 8, g_str16                         'Recipient State
    TransactionBuilder strTrans, 9, g_str17                         'Recipient Zip
    TransactionBuilder strTrans, 183, g_str18                       'Recipient Phone
    TransactionBuilder strTrans, 12, g_str32Return                  'Return Contact Name
    TransactionBuilder strTrans, 11, g_str4Return                   'Return Company Name
    TransactionBuilder strTrans, 13, g_str5Return                   'Return Addr1
    TransactionBuilder strTrans, 14, g_str6Return                   'Return Addr2
    TransactionBuilder strTrans, 15, g_str7Return                   'Return City
    TransactionBuilder strTrans, 16, g_str8Return                   'Return State
    TransactionBuilder strTrans, 17, g_str9Return                   'Return Zip
    TransactionBuilder strTrans, 50, g_str117Return                 'Return Country
    TransactionBuilder strTrans, 18, g_str183Return                 'Return Phone
    TransactionBuilder strTrans, 23, g_str23Return                                      'Pay Type
    TransactionBuilder strTrans, 20, g_str20Return                                      'Bill-To Acct#
    TransactionBuilder strTrans, 1670, RemoveSpecial(ImpliedDecimal(g_str1670))         'Weight                              'Weight
    
    ' 2008-09-28, JFW
    TransactionBuilder strTrans, 75, g_str75                            'Weight type
    
    TransactionBuilder strTrans, 1274, g_str1274Return                                  'Service Type
    TransactionBuilder strTrans, 1273, g_str1273Return                                  'Packaging Type
    TransactionBuilder strTrans, 25, g_str25                                            'References
    TransactionBuilder strTrans, 3056, g_str3056                                        'P.O. Number
    TransactionBuilder strTrans, 3057, g_str3057                                        'Invoice Number
    TransactionBuilder strTrans, 2210, g_str2210                                        'RMA #
    TransactionBuilder strTrans, 38, g_str38                                            'Department Notes
    TransactionBuilder strTrans, 10, g_str10                                            'Acct Number
    TransactionBuilder strTrans, 1202, g_str1202                                        'Recipient Email
    TransactionBuilder strTrans, 2392, g_str2392                                        'Returning Party Email
    TransactionBuilder strTrans, 2388, g_str2388                                        'Email Message
    TransactionBuilder strTrans, 1333, "Y"                                              'Drop-Off Flag
    TransactionBuilder strTrans, 1398, g_str1398                                        'Item Description
    TransactionBuilder strTrans, 2389, g_str2389                                        'Merchant Contact Phone
    If IsDate(g_str2387) Then
        TransactionBuilder strTrans, 2387, Format(g_str2387, "YYYYMMDD")                'Label Expiration Date
    End If
    '4/26/06 Added DIM fields for Freight
    TransactionBuilder strTrans, 57, g_str57                            'DIM H
    TransactionBuilder strTrans, 58, g_str58                            'DIM W
    TransactionBuilder strTrans, 59, g_str59                            'DIM L
    TransactionBuilder strTrans, 99, ""                                 'End of Transaction
    
    BuildOnlineReturnLabel = strTrans

    Exit Function
EH:
     MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildOnlineReturnLabel"

End Function
'---------------------------------------------------------------------------------------
' Module    : BuildTagTrans
' DateTime  : 1/25/2006
' Author    : Chris Elwell
' Purpose   : Builds and returns the fields required for a Call Tag or Express Tag.
'---------------------------------------------------------------------------------------
'
Public Function BuildTagTrans(ByVal blnCallTag As Boolean) As String
    Dim strTrans As String
    Dim strQuery
    Dim rsTags As New ADODB.Recordset
    Dim i As Integer
    
    On Error GoTo EH
    
    'Build the FXRS transaction *** REVERSE SHIPPER AND RECIPIENT FIELDS
    strTrans = ""
    'Ground call tag specific fields
    If blnCallTag Then
        TransactionBuilder strTrans, 0, "044"                           'Transaction type
        'Get mutli-occurence fields
        strQuery = "SELECT * FROM TagsMulti WHERE f1 = '" & g_str1 & "' And Workstation = '" & g_strComputerName & "'"
        
        rsTags.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
        i = 1
        Do Until rsTags.EOF
            TransactionBuilder strTrans, "1398-" & Trim(Str(i)), rsTags!f1398                   'Item Description
            TransactionBuilder strTrans, "1415-" & Trim(Str(i)), ImpliedDecimal(rsTags!f1415)   'Item Dec Val
        
            rsTags.MoveNext
            i = i + 1
        Loop
        TransactionBuilder strTrans, 3231, g_str3231                    'Res P/U flag
    'Express Tag specific fields
    Else
        TransactionBuilder strTrans, 0, "046"                       'Transaction type
        TransactionBuilder strTrans, 1400, g_str1400                'Total Weight                              'Weight
        TransactionBuilder strTrans, 1415, g_str1415                'Total Dec Val
        TransactionBuilder strTrans, 1200, g_str1200                'HAL Flag
        TransactionBuilder strTrans, 1266, g_str1266                'Sat Del Flag
        TransactionBuilder strTrans, 1274, g_str1274                'Service type
        TransactionBuilder strTrans, 1273, g_str1273                'Pkg type
        TransactionBuilder strTrans, 75, "LBS"                      'Wgt type
    End If
    TransactionBuilder strTrans, 1, g_str1                          'Transaction ID
    TransactionBuilder strTrans, 50, g_str50                        'Country - 2 character code
    TransactionBuilder strTrans, 32, g_str12                        'Recipient Contact
    TransactionBuilder strTrans, 4, g_str11                         'Recipient Company Name
    TransactionBuilder strTrans, 5, g_str13                         'Recipient Addr1
    TransactionBuilder strTrans, 6, g_str14                         'Recipient Addr2
    TransactionBuilder strTrans, 7, g_str15                         'Recipient City
    TransactionBuilder strTrans, 8, g_str16                         'Recipient State
    TransactionBuilder strTrans, 9, g_str17                         'Recipient Zip
    TransactionBuilder strTrans, 183, g_str18                       'Recipient Phone
    TransactionBuilder strTrans, 12, g_str32Return                  'Return Contact Name
    TransactionBuilder strTrans, 11, g_str4Return                   'Return Company Name
    TransactionBuilder strTrans, 13, g_str5Return                   'Return Addr1
    TransactionBuilder strTrans, 14, g_str6Return                   'Return Addr2
    TransactionBuilder strTrans, 15, g_str7Return                   'Return City
    TransactionBuilder strTrans, 16, g_str8Return                   'Return State
    TransactionBuilder strTrans, 17, g_str9Return                   'Return Zip
    TransactionBuilder strTrans, 18, g_str183Return                 'Return Phone
    TransactionBuilder strTrans, 23, g_str23Return                  'Pay Type
    TransactionBuilder strTrans, 20, g_str20Return                  'Bill-To Acct#
    TransactionBuilder strTrans, 1009, g_str1009                    'Last P/U Time
    TransactionBuilder strTrans, 1008, g_str1008                    'Pkg Ready Time
    TransactionBuilder strTrans, 25, g_str25                        'References
    TransactionBuilder strTrans, 1365, g_str1365                    'Dispatch date
    TransactionBuilder strTrans, 1010, g_str1010                    'P/U Instructions
    TransactionBuilder strTrans, 2210, g_str2210                    'RMA #
    TransactionBuilder strTrans, 10, g_str10                        'Acct Number
    TransactionBuilder strTrans, 498, g_str498                      'Meter Number
    TransactionBuilder strTrans, 1090, "USD"                        'Dec Val currency
    TransactionBuilder strTrans, 68, "USD"                          'Rating currency
    TransactionBuilder strTrans, 116, g_str116                      '# pkgs
    TransactionBuilder strTrans, 440, g_str440                      'Res flag
    TransactionBuilder strTrans, 117, "US"                          'Shipper Country
    
    TransactionBuilder strTrans, 99, ""                             'End of Transaction
    
    BuildTagTrans = strTrans

Release:
    If rsTags.State = adStateOpen Then rsTags.Close
    Set rsTags = Nothing
    Exit Function
EH:
     MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildTagTrans"
     Resume Release

End Function
'---------------------------------------------------------------------------------------
' Module    : BuildCancelTagTrans
' DateTime  : 1/25/2006
' Author    : Chris Elwell
' Purpose   : Builds and returns the fields required for a Call Tag pr Express Tag.
'---------------------------------------------------------------------------------------
'
Public Function BuildCancelTagTrans(ByVal str1011 As String, ByVal str29 As String) As String
                                    
    On Error GoTo EH
    
    Dim strTrans As String
    Dim strQuery
    Dim rsTag As New ADODB.Recordset
    
    strQuery = "SELECT Type, f10, f498, f1365, f1012 FROM Tags WHERE f1011 = " & SingleQuotes(str1011)
    strQuery = strQuery + " AND f29 = " & SingleQuotes(str29)
    
    rsTag.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    
    strTrans = ""
    
    If Not rsTag.EOF Then
        'Call Tag Cancel
        If rsTag!Type = "CT" Then
            TransactionBuilder strTrans, 0, "045"                   'Transaction type
        'Express Tag Cancel
        Else
            TransactionBuilder strTrans, 0, "047"                   'Transaction type
            TransactionBuilder strTrans, 1365, rsTag!f1365          'Dispatch date
            TransactionBuilder strTrans, 1012, rsTag!f1012          'Dispatch location
        End If
        TransactionBuilder strTrans, 1, str1011                     'Trans ID (Dispatch #)
        TransactionBuilder strTrans, 1011, str1011                  'Dispatch #
        TransactionBuilder strTrans, 10, rsTag!f10                  'Acct Number
        TransactionBuilder strTrans, 498, rsTag!f498                'Meter Number
        TransactionBuilder strTrans, 99, ""                         'End of Transaction
    End If
    
    BuildCancelTagTrans = strTrans
    
Release:
    If rsTag.State = adStateOpen Then rsTag.Close
    Set rsTag = Nothing
    Exit Function
EH:
     MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildCancelTagTrans"
     Resume Release

End Function
'---------------------------------------------------------------------------------------
' Module    : BuildRateTrans
' DateTime  : 6/11/2004
' Modified  : 20070328-02 Addded strType for new Service Quote
' Author    : Chris Elwell
' Purpose   : Builds and returns the transaction string for Rating a shipment from the
'             Ship form.
'---------------------------------------------------------------------------------------
'
Public Function BuildRateTrans(ByVal strType As String) As String
    Dim strTrans As String
    Dim i As Integer
    Dim rsMPS As New ADODB.Recordset
    Dim strQuery As String
    '2010-05-19, JFW, TD express rate quote all weight to total
    Dim dblTotalWeight As Double
    
    On Error GoTo EH
    
    'Set Svc Code global
    g_str1274 = IIf(strType = "RATE ONLY", g_str1274, Right(strType, 2))
    
    'For Service Quote have to set the Order ID to the value passed in strType for MPS
    g_str1 = IIf(Left(strType, 5) = "QUOTE", strType, g_str1)
    
    'Get MPS fields
    strQuery = "SELECT * FROM MPS WHERE f1 = " & SingleQuotes(IIf(Left(strType, 5) = "QUOTE", "QUOTE", g_str1))
    strQuery = strQuery & " AND Workstation = '" & g_strComputerName & "'"
    strQuery = strQuery & " order by ShipDate"

    rsMPS.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    
    If rsMPS.BOF Then
        rsMPS.Close
        'Get MPS fields
        strQuery = "SELECT * FROM MPS WHERE f1 = " & SingleQuotes(IIf(frmShip.f1.Visible, frmShip.f1, frmShip.cboCustID))
        strQuery = strQuery & " AND Workstation = '" & g_strComputerName & "'"
        strQuery = strQuery & " order by ShipDate"
        rsMPS.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    End If
    
    'Build the FXRS transaction
    strTrans = ""
    TransactionBuilder strTrans, 0, "020"                           'Transaction type
    TransactionBuilder strTrans, 1, strType                         'Transaction ID
    TransactionBuilder strTrans, 8, g_str8                          'Shipper State
    TransactionBuilder strTrans, 9, g_str9                          'Shipper Zip
    TransactionBuilder strTrans, 117, g_str117                      'Shipper Country
    TransactionBuilder strTrans, 10, g_str10                        'Acct Number
    ' 2011-04-12, JFW, FSMS 1062 bug on TD Ground rate giving error, try meter number.
    TransactionBuilder strTrans, 498, g_str498
    TransactionBuilder strTrans, 16, g_str16                        'Recipient State
    TransactionBuilder strTrans, 17, g_str17                        'Recipient Zip
    TransactionBuilder strTrans, 50, g_str50                        'Country - 2 character code
    
    '2006-10-04, JFW, TD rate quote with FXRS 0800
    If frmShip.f1482.Value = 1 Then
        TransactionBuilder strTrans, 541, "NYYYNNNNN"                               'Open Ship Flags
        TransactionBuilder strTrans, 542, g_strTDOpenShip
    End If
    
    'Rate duplicate pkgs
    If Val(g_str116) > 1 And frmShip.chkDuplicate = 1 Then
        For i = 1 To CInt(g_str116)
            TransactionBuilder strTrans, "1670-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(g_str1670))          'Weight
        Next
    'Rate MPS
    ElseIf Val(g_str116) > 1 And rsMPS.RecordCount > 0 Then
        
        i = 1
        
        Do Until rsMPS.EOF
            '2010-05-19, JFW, TD express rate quote all weight to total
            '            If frmShip.f1482.Value = 1 Then
            '                If g_str1274 = "90" Or g_str1274 = "92" Then
            '                    TransactionBuilder strTrans, "1670-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(rsMPS!g_str1670))          'Weight
            '                Else
            '                    If IsNumeric(rsMPS!g_str1670 & "") Then
            '                        dblTotalWeight = dblTotalWeight + CDbl(rsMPS!g_str1670 & "")
            '                    End If
            '                End If
            '            Else
            '                TransactionBuilder strTrans, "1670-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(rsMPS!g_str1670))          'Weight
            '            End If
            '2010-05-21, JFW, FSMS 1000 OK
            TransactionBuilder strTrans, "1670-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(rsMPS!g_str1670))          'Weight
            
            TransactionBuilder strTrans, "57-" & Trim(Str(i)), rsMPS!g_str57 & ""          'DIM
            TransactionBuilder strTrans, "58-" & Trim(Str(i)), rsMPS!g_str58 & ""          'DIM
            TransactionBuilder strTrans, "59-" & Trim(Str(i)), rsMPS!g_str59 & ""          'DIM
            Select Case rsMPS!g_str2399
                Case "IDR"
                    TransactionBuilder strTrans, "2399-" & Trim(Str(i)), "2"                    'Indirect Sig Req
                Case "DSR"
                    TransactionBuilder strTrans, "2399-" & Trim(Str(i)), "3"                    'Direct Sig Req
                Case "ASR"
                    TransactionBuilder strTrans, "2399-" & Trim(Str(i)), "4"                    'Adult Sig Req
            End Select
            'Add handling charge fields for use with doc-tab
            With frmSetup
                If .chkAddHndlChg = 1 Then
                    If .f1588(1) Then
                        TransactionBuilder strTrans, "1588-" & Trim(Str(i)), "1"                  'Handling charge Type - flat amount
                    ElseIf .f1588(2) Then
                        TransactionBuilder strTrans, "1588-" & Trim(Str(i)), "2"                  'Handling charge Type - % of freight chg
                    ElseIf .f1588(3) Then
                        TransactionBuilder strTrans, "1588-" & Trim(Str(i)), "3"                  'Handling charge Type - % of Net chg
                    End If
                    'Handling chg application point
                    If .f1606(0) Then
                        TransactionBuilder strTrans, "1606-" & Trim(Str(i)), "0"                  'Apply to pkg
                    ElseIf .f1606(1) Then
                        TransactionBuilder strTrans, "1606-" & Trim(Str(i)), "1"                  'Apply to shipment
                    End If
                    
                    If .chkBySvc = 0 Then
                        TransactionBuilder strTrans, "1595-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(.f1595(0)))            'All services have same handling chg
                    Else
                        Select Case g_str1274
                            Case "06"
                                TransactionBuilder strTrans, "1595-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(.f1595(0)))        'FO amount
                            Case "01"
                                TransactionBuilder strTrans, "1595-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(.f1595(1)))        'PO amount
                            Case "05"
                                TransactionBuilder strTrans, "1595-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(.f1595(2)))        'SO amount
                            Case "03"
                                TransactionBuilder strTrans, "1595-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(.f1595(3)))        'ES amount
                            Case "20"
                                TransactionBuilder strTrans, "1595-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(.f1595(4)))        'XS amount
                            Case "92"
                                TransactionBuilder strTrans, "1595-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(.f1595(5)))        'GR amount
                            Case "90"
                                TransactionBuilder strTrans, "1595-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(.f1595(6)))        'HD amount
                        End Select
                    End If
                End If
            End With
            '2010-05-19, JFW, TD express rate quote all weight to total
            '2010-05-21, JFW, FSMS 1000 OK
            '            If dblTotalWeight > 0 Then
            '                TransactionBuilder strTrans, "1670", RemoveSpecial(ImpliedDecimal(dblTotalWeight))
            '            End If
            'Total Declared Value
            g_str26 = Str(Val(g_str26) + Val(rsMPS!g_str26 & ""))
                
            i = i + 1
            rsMPS.MoveNext
        Loop
    'Single piece and Intl Non-MPS rate
    Else
        TransactionBuilder strTrans, 1670, RemoveSpecial(ImpliedDecimal(g_str1670))                'Weight
        TransactionBuilder strTrans, 57, g_str57                        'DIM H
        TransactionBuilder strTrans, 58, g_str58                        'DIM W
        TransactionBuilder strTrans, 59, g_str59                        'DIM L
        TransactionBuilder strTrans, 1208, g_str1208                    'Sig Req Flag
        TransactionBuilder strTrans, 2399, g_str2399                    'Sig Req Type
        'Add handling charge fields for use with doc-tab
        With frmSetup
            If .chkAddHndlChg = 1 Then
                If .f1588(1) Then
                    TransactionBuilder strTrans, 1588, "1"                  'Handling charge Type - flat amount
                ElseIf .f1588(2) Then
                    TransactionBuilder strTrans, 1588, "2"                  'Handling charge Type - % of freight chg
                ElseIf .f1588(3) Then
                    TransactionBuilder strTrans, 1588, "3"                  'Handling charge Type - % of Net chg
                End If
                'Handling chg application point
                If .f1606(0) Then
                    TransactionBuilder strTrans, 1606, "0"                  'Apply to pkg
                ElseIf .f1606(1) Then
                    TransactionBuilder strTrans, 1606, "1"                  'Apply to shipment
                End If
                
                If .chkBySvc = 0 Then
                    TransactionBuilder strTrans, 1595, RemoveSpecial(ImpliedDecimal(.f1595(0)))            'All services have same handling chg
                Else
                    Select Case g_str1274
                        Case "06"
                            TransactionBuilder strTrans, 1595, RemoveSpecial(ImpliedDecimal(.f1595(0)))        'FO amount
                        Case "01"
                            TransactionBuilder strTrans, 1595, RemoveSpecial(ImpliedDecimal(.f1595(1)))        'PO amount
                        Case "05"
                            TransactionBuilder strTrans, 1595, RemoveSpecial(ImpliedDecimal(.f1595(2)))        'SO amount
                        Case "03"
                            TransactionBuilder strTrans, 1595, RemoveSpecial(ImpliedDecimal(.f1595(3)))        'ES amount
                        Case "20"
                            TransactionBuilder strTrans, 1595, RemoveSpecial(ImpliedDecimal(.f1595(4)))        'XS amount
                        Case "92"
                            TransactionBuilder strTrans, 1595, RemoveSpecial(ImpliedDecimal(.f1595(5)))        'GR amount
                        Case "90"
                            TransactionBuilder strTrans, 1595, RemoveSpecial(ImpliedDecimal(.f1595(6)))        'HD amount
                    End Select
                End If
            End If
        End With
    End If
'    TransactionBuilder strTrans, 116, g_str116                        '# pkgs
    TransactionBuilder strTrans, 26, Trim(Str(CLng(Val(g_str26))))     'Declared Value
    TransactionBuilder strTrans, 23, g_str23                        'Pay Type
    'Send $1 for COD Amount if COD is selected.
    If g_str27 = "Y" Then
        TransactionBuilder strTrans, 27, g_str27                    'COD Flag
        TransactionBuilder strTrans, 53, "100"                      'COD Amount
    End If
    TransactionBuilder strTrans, 75, g_str75                        'Weight Type
    TransactionBuilder strTrans, 440, g_str440                      'Residential flag
    TransactionBuilder strTrans, 1090, g_str1090                    'Currency type
    If strType = "RATE ONLY" Then
        TransactionBuilder strTrans, 1234, "1"                      'Rate Flag
    Else
        TransactionBuilder strTrans, 1234, "3"                      'Rate/Route Flag
    End If
    TransactionBuilder strTrans, 1266, g_str1266                    'Sat Del Flag
    TransactionBuilder strTrans, 1273, g_str1273                    'Packaging Type
    TransactionBuilder strTrans, 1958, g_str1958                    'Admissibility Pkg Type
    If g_str1274 = "18" Then
        TransactionBuilder strTrans, 1274, "01"                    'Service Type
    Else
        TransactionBuilder strTrans, 1274, g_str1274                    'Service Type
    End If
    
    TransactionBuilder strTrans, 3018, g_str3018                    'Non-Standard Packaging
    TransactionBuilder strTrans, 3020, g_str3020                    'FHD Special SVCs
    TransactionBuilder strTrans, 99, ""                             'End of Transaction

    BuildRateTrans = strTrans

Release:

    If rsMPS.State = adStateOpen Then rsMPS.Close
    Set rsMPS = Nothing
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildRateTrans"
    Resume Release
    
End Function
'---------------------------------------------------------------------------------------
' Procedure : BuildCloseTrans
' DateTime  : 12/17/2003
' Modified  : 03/16/2006
' Purpose   : Sends a Close transaction to FXRS
'---------------------------------------------------------------------------------------
'
Public Function BuildCloseTrans(ByVal strAcctNum As String, Optional ByVal strCloseType As String = "", Optional strMeterNum As String = "") As String
    Dim strTrans As String
    
    On Error GoTo EH
    
    strTrans = ""
    TransactionBuilder strTrans, 0, "007"               'Transaction type
    TransactionBuilder strTrans, 1, "Close"             'Transaction ID
    If strAcctNum <> "" Then
        '03/16/06 Changed from meter# to acct#
        TransactionBuilder strTrans, 10, strAcctNum         'Meter Number
    End If
    If strMeterNum <> "" Then
        TransactionBuilder strTrans, 498, strMeterNum         'Meter Number
    End If
    If strCloseType <> "" Then
        TransactionBuilder strTrans, 3025, strCloseType     'Close Type
    End If
    TransactionBuilder strTrans, 99, ""                 'End of Transaction
    
    BuildCloseTrans = strTrans
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildCloseTrans"

End Function
'---------------------------------------------------------------------------------------
' Procedure : BuildIPDCreateTrans
' DateTime  : 3/17/2005
' Purpose   : Builds an IPD MAWB Transaction
'---------------------------------------------------------------------------------------
'
Public Function BuildIPDCreateTrans() As String
    Dim strTrans As String
    
    On Error GoTo EH
    
    strTrans = ""
        
    TransactionBuilder strTrans, 0, "020"                   'Trans type
    TransactionBuilder strTrans, 1, "IPD MAWB CREATE"       'TransID
    TransactionBuilder strTrans, 23, g_str23                'Bill-To Type
    TransactionBuilder strTrans, 20, g_str20                'Bill-To Acct#
    TransactionBuilder strTrans, 50, g_str50                'Recip Country
    TransactionBuilder strTrans, 68, g_str68                'Currency Type
    TransactionBuilder strTrans, 70, g_str70                'Duty/Tax Pay Type
    TransactionBuilder strTrans, 71, g_str71                'Duty/Tax Acct#
    TransactionBuilder strTrans, 72, g_str72                'Terms of Sale
    TransactionBuilder strTrans, 75, g_str75                'Weight type
    'Modified 6/7 to pass "N" if processing MPS for IPD
    If g_str113 = "" Or frmSetup.chkIPDMPS = 1 Then
        TransactionBuilder strTrans, 113, "N"               'CI Flag
    Else
        TransactionBuilder strTrans, 113, "Y"               'CI Flag
    End If
    '02/27/06 Added for future day shipping
    If IsDate(g_str24) Then
        TransactionBuilder strTrans, 24, Format(g_str24, "YYYYMMDD")                    'Ship Date Note yyyymmdd format, no punctuation
    Else
        TransactionBuilder strTrans, 24, g_str24                                        'Ship Date Note yyyymmdd format, no punctuation
    End If

    TransactionBuilder strTrans, 10, g_str10                'Acct #
    TransactionBuilder strTrans, 541, "YNNNNNNNN"           'Open Ship Flag
    TransactionBuilder strTrans, 1274, "18"                 'Service Type
    TransactionBuilder strTrans, 1297, g_str1297            'Customer Inv #
    TransactionBuilder strTrans, 1355, g_str1355            'IOR Facility Code
    TransactionBuilder strTrans, 1349, g_str1349            'AES Filing Status
    TransactionBuilder strTrans, 1358, g_str1358            'ITN/FTSR
    If g_str1592 = "Y" And g_str113 <> "Y" Then
        TransactionBuilder strTrans, 1592, "Y"              'Override Customs Val Flag
    End If
    
    'Added 3/28/05 for Alt Return Addr fields
    'Removed 4/24/06 moved to BuildIPDShipTrans for piece level
'    If g_str1586 = "Y" Then
'        TransactionBuilder strTrans, 1586, g_str1586        'Print Alt Return flag
'        TransactionBuilder strTrans, 1485, g_str1485        'Alt Return Contact
'        TransactionBuilder strTrans, 1486, g_str1486        'Alt Return Company
'        TransactionBuilder strTrans, 1487, g_str1487        'Alt Return Addr1
'        TransactionBuilder strTrans, 1488, g_str1488        'Alt Return Addr2
'        TransactionBuilder strTrans, 1489, g_str1489        'Alt Return City
'        TransactionBuilder strTrans, 1490, g_str1490        'Alt Return State
'        TransactionBuilder strTrans, 1491, g_str1491        'Alt Return Zip
'        TransactionBuilder strTrans, 1492, g_str1492        'Alt Return Phone
'        TransactionBuilder strTrans, 1585, g_str1585        'Alt Return Country
'    End If
    
    'Added 8/16/05 for Admissibility pkg type default for CA
    If g_str50 = "CA" Or g_str50 = "US" Then
        TransactionBuilder strTrans, 1958, "Box"                'Admissibility Pkg Type
    End If
    TransactionBuilder strTrans, 99, ""                     'End of Transaction
    
    BuildIPDCreateTrans = strTrans
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildIPDCreateTrans"
End Function

'---------------------------------------------------------------------------------------
' Procedure : BuildIPDShipTrans
' DateTime  : 10/26/2004
' Purpose   : Builds an IPD CRN Add Transaction
'---------------------------------------------------------------------------------------
'
Public Function BuildIPDShipTrans(ByVal strOrderNum As String) As String
    Dim strTrans As String
    Dim strQuery As String
    Dim rsCommodity As New ADODB.Recordset
    Dim rsIntlMPS As New ADODB.Recordset
    Dim boolTDMPS3056 As Boolean
    Dim boolTDMPS3057 As Boolean
    Dim i As Integer ' Package count
    Dim j As Integer ' Commodity count
    Dim intQuantityToShip As Integer
    Dim intQuantityNow As Integer
    
    On Error GoTo EH
    
    strQuery = "SELECT * FROM IntlCommodities WHERE f1 = '" & strOrderNum & "'"
    strQuery = strQuery & " AND Workstation = '" & g_strComputerName & "'"
    strQuery = strQuery & " AND (g_str29 IS NULL OR g_str29 = '')"
    
    rsCommodity.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    
    If CheckIntlCommodities(rsCommodity) <> "" Then
        Err.Raise 12345, "BuildIPDShipTrans", CheckIntlCommodities(rsCommodity)
    End If
    
    'Build the common fields
    strTrans = BuildCommonFlds
        
    TransactionBuilder strTrans, 1116, g_str1116            'DIM Units
    
    'Build the Intl MPS fields
    TransactionBuilder strTrans, 1358, g_str1358            'ITN/FTSR
    TransactionBuilder strTrans, 413, g_str413              'NAFTA Flag
    TransactionBuilder strTrans, 75, g_str75                'Weight type
    TransactionBuilder strTrans, 72, "1"                    'Terms of Sale
    '04/25/06 If printing the CI include CI fields from Intl tab
    If g_str113 = "Y" Then
        TransactionBuilder strTrans, "418-1", g_str418_1        'CI Comments 1
        TransactionBuilder strTrans, "418-2", g_str418_2        'CI Comments 2
        TransactionBuilder strTrans, "418-3", g_str418_3        'CI Comments 3
        TransactionBuilder strTrans, 532, RemoveSpecial(ImpliedDecimal(g_str532))   'CI Freight Charge
        TransactionBuilder strTrans, 533, RemoveSpecial(ImpliedDecimal(g_str533))   'CI Insurance Charge
        TransactionBuilder strTrans, 534, RemoveSpecial(ImpliedDecimal(g_str534))   'CI Other Charge
        TransactionBuilder strTrans, 1357, g_str1357            'Misc Chg Type
    End If
    
    'Loop through Intl MPS
    i = 1
    
    strQuery = "SELECT * FROM MPS WHERE f1 = '" & strOrderNum & "'"
    strQuery = strQuery & " AND Workstation = '" & g_strComputerName & "'"
    strQuery = strQuery & " order by ShipDate"
    
    rsIntlMPS.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    'If using the MPS form get values from recordset
    If rsIntlMPS.RecordCount > 0 Then
        ' 2010-04-27, JFW, Express package count on TD MPS
        If frmShip.f1482.Value = True Then
            If g_str1274 <> "92" And g_str1274 <> "90" Then
                boolTDMPS3056 = True
                boolTDMPS3057 = True
                Do Until rsIntlMPS.EOF
                    If rsIntlMPS!g_str3056 & "" <> "" Then boolTDMPS3056 = False
                    If rsIntlMPS!g_str3057 & "" <> "" Then boolTDMPS3057 = False
                    rsIntlMPS.MoveNext
                Loop
                rsIntlMPS.MoveFirst
                If boolTDMPS3057 Then boolTDMPS3056 = False
            End If
        End If
        Do Until rsIntlMPS.EOF
            TransactionBuilder strTrans, "57-" & Trim(Str(i)), rsIntlMPS!g_str57 & ""            'CI Freight Charge
            TransactionBuilder strTrans, "58-" & Trim(Str(i)), rsIntlMPS!g_str58 & ""            'CI Insurance Charge
            TransactionBuilder strTrans, "59-" & Trim(Str(i)), rsIntlMPS!g_str59 & ""            'CI Other Charge
            TransactionBuilder strTrans, "1670-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(rsIntlMPS!g_str1670)) & ""
            TransactionBuilder strTrans, "26-" & Trim(Str(i)), rsIntlMPS!g_str26 & ""            'References
            TransactionBuilder strTrans, "25-" & Trim(Str(i)), rsIntlMPS!g_str25 & ""            'References
            If boolTDMPS3056 Then
                TransactionBuilder strTrans, "3056-" & Trim(Str(i)), "Pkg " & i & " of " & rsIntlMPS.RecordCount
            Else
                TransactionBuilder strTrans, "3056-" & Trim(Str(i)), rsIntlMPS!g_str3056 & ""        'P.O. #
            End If
            If boolTDMPS3057 Then
                TransactionBuilder strTrans, "3057-" & Trim(Str(i)), "Pkg " & i & " of " & rsIntlMPS.RecordCount
            Else
                TransactionBuilder strTrans, "3057-" & Trim(Str(i)), rsIntlMPS!g_str3057 & ""        'Inv #
            End If
            'Added 6/16/05 for Sig Svc options
            Select Case rsIntlMPS!g_str2399
                Case "IDR"
                    TransactionBuilder strTrans, "2399-" & Trim(Str(i)), "2"                    'Indirect Sig Req
                Case "DSR"
                    TransactionBuilder strTrans, "2399-" & Trim(Str(i)), "3"                    'Direct Sig Req
                Case "ASR"
                    TransactionBuilder strTrans, "2399-" & Trim(Str(i)), "4"                    'Adult Sig Req
            End Select
        
'            'Total Declared Value
'            g_str26 = Str(Val(g_str26) + Val(rsIntlMPS!g_str26 & ""))
            
            If rsIntlMPS("g_str3018") = 1 Then
                 TransactionBuilder strTrans, "3018-" & Trim(Str(i)), "Y"                        'Non-standard pkging
            End If

'            '8/17/05 Ground COD on subsequent MPS pieces -- added by Mark Waldmann #451355
'            ' 2010-04-27, JFW, For use by TD MPS
'            If frmShip.f1482.Value = True Then
'                If g_str1274 = "92" And g_str27 = "Y" Then
'                    If frmCOD.chkCOD1stPiece = 0 Then
'                        If g_str3014 = "Y" Then
'                            TransactionBuilder strTrans, "3014-" & Trim(Str(i)), g_str3014           'ECOD Flag
'                        Else
'                            TransactionBuilder strTrans, "27-" & Trim(Str(i)), g_str27               'COD Flag
'                        End If
'                        TransactionBuilder strTrans, "53-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(g_str53))  'COD amount for each package in Ground shipment
'                    End If
'                End If
'            End If
            
'            If i > 1 Then
'                ' TransactionBuilder strTrans, "78-" & Trim(Str(i)) & "-1", RemoveSpecial(ImpliedDecimal(1))         'Commodity Customs Value
'                TransactionBuilder strTrans, "79-" & Trim(Str(i)) & "-1", "Additional package"       'Description
'                TransactionBuilder strTrans, "80-" & Trim(Str(i)) & "-1", "CA"                           'Country of Manu
'                TransactionBuilder strTrans, "82-" & Trim(Str(i)) & "-1", "1"                           'Quantity
'                TransactionBuilder strTrans, "414-" & Trim(Str(i)) & "-1", "EA"                         'Unit of Measure
'                TransactionBuilder strTrans, "1030-" & Trim(Str(i)) & "-1", RemoveSpecial(ImpliedDecimal(0.01, 6))        'Commodity Unit Value
'                ' TransactionBuilder strTrans, "1275-" & Trim(Str(i)) & "-1" , rsCommodity!g_str1275 & ""                        'Unit of Measure
'                ' TransactionBuilder strTrans, "120-" & Trim(Str(i)) & "-1" , rsCommodity!g_str120 & ""                        'Unit of Measure
'            End If
            
            i = i + 1
            rsIntlMPS.MoveNext
        Loop
'        TransactionBuilder strTrans, 26, Trim(Str(CLng(Val(g_str26))))       'Carriage Value
    'Else get values from main form
    Else
        TransactionBuilder strTrans, 116, g_str116                          '# of Pkgs
    End If
        
    'Loop through commodities
    i = 1
    j = 1
    g_str119 = "0"
    If Not rsCommodity.EOF Then
        intQuantityToShip = CLng(rsCommodity!g_str82 & "")
        If i >= rsIntlMPS.RecordCount Then
            ' Single or last package, all of commodity
            intQuantityNow = intQuantityToShip
        Else
            ' MPS then one bit of commodity
            intQuantityNow = 1
        End If
    End If
    
    Do While Not rsCommodity.EOF
        If g_str75 = "LBS" Then
            TransactionBuilder strTrans, "77-" & i & "-" & Trim(Str(j)), RoundUp(rsCommodity!g_str77) & ""             'Commodity Weight
        Else
            TransactionBuilder strTrans, "77-" & i & "-" & Trim(Str(j)), RemoveSpecial(ImpliedDecimal(rsCommodity!g_str77, 1)) & ""         'Terms of Sale
        End If
        ' TransactionBuilder strTrans, "78-" & i & "-" & Trim(Str(j)), RemoveSpecial(ImpliedDecimal(rsCommodity!g_str78)) & ""       'Commodity Customs Value
        TransactionBuilder strTrans, "79-" & i & "-" & Trim(Str(j)), rsCommodity!g_str79 & ""                          'Description
        TransactionBuilder strTrans, "80-" & i & "-" & Trim(Str(j)), rsCommodity!g_str80 & ""                          'Country of Manu
        TransactionBuilder strTrans, "81-" & i & "-" & Trim(Str(j)), rsCommodity!g_str81 & ""                          'Harmonized Code
        TransactionBuilder strTrans, "82-" & i & "-" & Trim(Str(j)), CStr(intQuantityNow) & ""                          'Quantity
        TransactionBuilder strTrans, "83-" & i & "-" & Trim(Str(j)), rsCommodity!g_str83 & ""                          'Export license #
        TransactionBuilder strTrans, "84-" & i & "-" & Trim(Str(j)), Format(rsCommodity!g_str84, "YYYYMMDD") & ""      'Export license Exp Date
        TransactionBuilder strTrans, "414-" & i & "-" & Trim(Str(j)), rsCommodity!g_str414 & ""                        'Unit of Measure
        TransactionBuilder strTrans, "1030-" & i & "-" & Trim(Str(j)), RemoveSpecial(ImpliedDecimal(rsCommodity!g_str1030, 6)) & ""       'Commodity Unit Value
        TransactionBuilder strTrans, "1275-" & i & "-" & Trim(Str(j)), rsCommodity!g_str1275 & ""                        'Unit of Measure
        TransactionBuilder strTrans, "120-" & i & "-" & Trim(Str(j)), rsCommodity!g_str120 & ""                        'Unit of Measure
        
        If IsNumeric(rsCommodity!g_str82) _
        And IsNumeric(rsCommodity!g_str1030) Then
            g_str119 = CDbl(g_str119) + intQuantityNow * CDbl(rsCommodity!g_str1030)
        End If
        
        ' Assign commodities to packages
        If i >= rsIntlMPS.RecordCount Then
            ' One package, or last package
            intQuantityToShip = intQuantityToShip = intQuantityNow
            If intQuantityToShip > 0 Then
                ' Ship all remaining of current commodity
                j = j + 1
                intQuantityNow = intQuantityToShip
            Else
                ' Ship next commodity
                rsCommodity.MoveNext
                If rsCommodity.EOF Then
                    intQuantityToShip = 1
                    intQuantityNow = 1
                Else
                    j = j + 1
                    intQuantityToShip = CLng(rsCommodity!g_str82 & "")
                    intQuantityNow = intQuantityToShip
                End If
            End If
        Else
            ' MPS package
            i = i + 1
            j = 1
            intQuantityToShip = intQuantityToShip - intQuantityNow
            If intQuantityToShip > 0 Then
                ' Ship some or all of current commodity
                If i >= rsIntlMPS.RecordCount Then
                    intQuantityNow = intQuantityToShip
                Else
                    intQuantityNow = 1
                End If
            Else
                ' Ship next commodity
                rsCommodity.MoveNext
                If rsCommodity.EOF Then
                    intQuantityToShip = 1
                    intQuantityNow = 1
                Else
                    intQuantityToShip = CLng(rsCommodity!g_str82 & "")
                    ' Ship some or all of this commodity
                    If i >= rsIntlMPS.RecordCount Then
                        intQuantityNow = intQuantityToShip
                    Else
                        intQuantityNow = 1
                    End If
                End If
            End If
        End If
        
    Loop
    
    If i < rsIntlMPS.RecordCount Then
        Err.Raise 12345, "BuildIPDShipTrans", "Insufficient commodities for " & rsIntlMPS.RecordCount & " packages."
    End If
    
    If g_str119 <> "" And g_str119 <> "0" Then
        TransactionBuilder strTrans, "119", g_str119
    End If
    
    TransactionBuilder strTrans, 541, "NNNYNNNNN"                               'Open Ship Flags
    TransactionBuilder strTrans, 1355, g_str1355                                'IOR Facility Code
    
    TransactionBuilder strTrans, 4574, "2"
    
'    'Added 9/13/05 for Alt Return Addr fields at the shipment level
    If g_str1586 = "Y" Then
        TransactionBuilder strTrans, 1586, g_str1586        'Print Alt Return flag
        TransactionBuilder strTrans, 1485, g_str1485        'Alt Return Contact
        TransactionBuilder strTrans, 1486, g_str1486        'Alt Return Company
        TransactionBuilder strTrans, 1487, g_str1487        'Alt Return Addr1
        TransactionBuilder strTrans, 1488, g_str1488        'Alt Return Addr2
        TransactionBuilder strTrans, 1489, g_str1489        'Alt Return City
        TransactionBuilder strTrans, 1490, g_str1490        'Alt Return State
        TransactionBuilder strTrans, 1491, g_str1491        'Alt Return Zip
        TransactionBuilder strTrans, 1492, g_str1492        'Alt Return Phone
        TransactionBuilder strTrans, 1585, g_str1585        'Alt Return Country
    End If
    
    TransactionBuilder strTrans, 99, ""                             'End of Transaction
    
    BuildIPDShipTrans = strTrans

Release:
    If rsCommodity.State = adStateOpen Then
        rsCommodity.Close
    End If
    Set rsCommodity = Nothing
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildIPDShipTrans"
    Resume Release
    
End Function

'---------------------------------------------------------------------------------------
' Procedure : BuildIPDShipTrans
' DateTime  : 10/26/2004
' Purpose   : Builds an IPD CRN Add Transaction
'---------------------------------------------------------------------------------------
'
Public Function BuildIPDShipTransColl(ByVal strOrderNum As String) As Collection

    Dim strTrans() As String
    Dim strTrans1 As String
    
    Dim strQuery As String
    Dim rsCommodity As New ADODB.Recordset
    Dim rsIntlMPS As New ADODB.Recordset
    Dim boolTDMPS3056 As Boolean
    Dim boolTDMPS3057 As Boolean
    Dim i As Integer ' Package count
    Dim j As Integer ' Commodity count
    Dim intQuantityToShip As Integer
    Dim intQuantityNow As Integer
    
    On Error GoTo EH
    
    strQuery = "SELECT * FROM IntlCommodities WHERE f1 = '" & strOrderNum & "'"
    strQuery = strQuery & " AND Workstation = '" & g_strComputerName & "'"
    strQuery = strQuery & " AND (g_str29 IS NULL OR g_str29 = '')"
    
    rsCommodity.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    
    If CheckIntlCommodities(rsCommodity) <> "" Then
        Err.Raise 12345, "BuildIPDShipTrans", CheckIntlCommodities(rsCommodity)
    End If
    
    'Build the common fields
    strTrans1 = BuildCommonFlds
        
    TransactionBuilder strTrans1, 1116, g_str1116            'DIM Units
    
    'Build the Intl MPS fields
    TransactionBuilder strTrans1, 1358, g_str1358            'ITN/FTSR
    TransactionBuilder strTrans1, 413, g_str413              'NAFTA Flag
    TransactionBuilder strTrans1, 75, g_str75                'Weight type
    TransactionBuilder strTrans1, 72, "1"                    'Terms of Sale
    '04/25/06 If printing the CI include CI fields from Intl tab
    If g_str113 = "Y" Then
        TransactionBuilder strTrans1, "418-1", g_str418_1        'CI Comments 1
        TransactionBuilder strTrans1, "418-2", g_str418_2        'CI Comments 2
        TransactionBuilder strTrans1, "418-3", g_str418_3        'CI Comments 3
        TransactionBuilder strTrans1, 532, RemoveSpecial(ImpliedDecimal(g_str532))   'CI Freight Charge
        TransactionBuilder strTrans1, 533, RemoveSpecial(ImpliedDecimal(g_str533))   'CI Insurance Charge
        TransactionBuilder strTrans1, 534, RemoveSpecial(ImpliedDecimal(g_str534))   'CI Other Charge
        TransactionBuilder strTrans1, 1357, g_str1357            'Misc Chg Type
    End If
    
    'Loop through Intl MPS
    i = 1
    
    strQuery = "SELECT * FROM MPS WHERE f1 = '" & strOrderNum & "'"
    strQuery = strQuery & " AND Workstation = '" & g_strComputerName & "'"
    strQuery = strQuery & " order by ShipDate"
    
    rsIntlMPS.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    'If using the MPS form get values from recordset
    If rsIntlMPS.RecordCount > 0 Then
    
        ReDim strTrans(rsIntlMPS.RecordCount)
        For i = 1 To rsIntlMPS.RecordCount
            strTrans(i) = strTrans1
        Next i
        i = 1
        
        ' 2010-04-27, JFW, Express package count on TD MPS
        If frmShip.f1482.Value = True Then
            If g_str1274 <> "92" And g_str1274 <> "90" Then
                boolTDMPS3056 = True
                boolTDMPS3057 = True
                Do Until rsIntlMPS.EOF
                    If rsIntlMPS!g_str3056 & "" <> "" Then boolTDMPS3056 = False
                    If rsIntlMPS!g_str3057 & "" <> "" Then boolTDMPS3057 = False
                    rsIntlMPS.MoveNext
                Loop
                rsIntlMPS.MoveFirst
                If boolTDMPS3057 Then boolTDMPS3056 = False
            End If
        End If
        Do Until rsIntlMPS.EOF
        
            TransactionBuilder strTrans(i), "57", rsIntlMPS!g_str57 & ""            'CI Freight Charge
            TransactionBuilder strTrans(i), "58", rsIntlMPS!g_str58 & ""            'CI Insurance Charge
            TransactionBuilder strTrans(i), "59", rsIntlMPS!g_str59 & ""            'CI Other Charge
            TransactionBuilder strTrans(i), "1670", RemoveSpecial(ImpliedDecimal(rsIntlMPS!g_str1670)) & ""
            TransactionBuilder strTrans(i), "26", rsIntlMPS!g_str26 & ""            'References
            TransactionBuilder strTrans(i), "25", rsIntlMPS!g_str25 & ""            'References
            If boolTDMPS3056 Then
                TransactionBuilder strTrans(i), "3056", "Pkg " & i & " of " & rsIntlMPS.RecordCount
            Else
                TransactionBuilder strTrans(i), "3056", rsIntlMPS!g_str3056 & ""        'P.O. #
            End If
            If boolTDMPS3057 Then
                TransactionBuilder strTrans(i), "3057", "Pkg " & i & " of " & rsIntlMPS.RecordCount
            Else
                TransactionBuilder strTrans(i), "3057", rsIntlMPS!g_str3057 & ""        'Inv #
            End If
            'Added 6/16/05 for Sig Svc options
            Select Case rsIntlMPS!g_str2399
                Case "IDR"
                    TransactionBuilder strTrans(i), "2399", "2"                    'Indirect Sig Req
                Case "DSR"
                    TransactionBuilder strTrans(i), "2399", "3"                    'Direct Sig Req
                Case "ASR"
                    TransactionBuilder strTrans(i), "2399", "4"                    'Adult Sig Req
            End Select
        
'            'Total Declared Value
'            g_str26 = Str(Val(g_str26) + Val(rsIntlMPS!g_str26 & ""))
            
            If rsIntlMPS("g_str3018") = 1 Then
                 TransactionBuilder strTrans(i), "3018", "Y"                        'Non-standard pkging
            End If

            If g_str187 = "388" Or g_str187 = "488" Then
                ' Reference                              Text              X                     Y                            Ref                                    ?                         Font
                strTrans(i) = strTrans(i) & "2429-4" & ",""03""2430-4" & ",""40""2431-4" & ",""" & CStr(265) & """2432-4" & ",""Pkg " & i & " of " & rsIntlMPS.RecordCount & """" & "2433-4" & ",""""" & "2434-4" & ",""" & CStr(8) & """"
            End If

            i = i + 1
            rsIntlMPS.MoveNext
        Loop
    'Else get values from main form
    Else
        TransactionBuilder strTrans1, 116, g_str116                          '# of Pkgs
        ReDim strTrans(1)
        strTrans(1) = strTrans1
    End If
        
    'Loop through commodities
    i = 1
    j = 1
    g_str119 = "0"
    If Not rsCommodity.EOF Then
        intQuantityToShip = CLng(rsCommodity!g_str82 & "")
        If i >= rsIntlMPS.RecordCount Then
            ' Single or last package, all of commodity
            intQuantityNow = intQuantityToShip
        Else
            ' MPS then one bit of commodity
            intQuantityNow = 1
        End If
    End If
    
    Do While Not rsCommodity.EOF
    
        If g_str75 = "LBS" Then
            TransactionBuilder strTrans(i), "77" & "-" & Trim(Str(j)), RoundUp(rsCommodity!g_str77) & ""             'Commodity Weight
        Else
            TransactionBuilder strTrans(i), "77" & "-" & Trim(Str(j)), RemoveSpecial(ImpliedDecimal(rsCommodity!g_str77, 1)) & ""         'Terms of Sale
        End If
        ' TransactionBuilder strTrans(i), "78" & "-" & Trim(Str(j)), RemoveSpecial(ImpliedDecimal(rsCommodity!g_str78)) & ""       'Commodity Customs Value
        TransactionBuilder strTrans(i), "79" & "-" & Trim(Str(j)), rsCommodity!g_str79 & ""                          'Description
        TransactionBuilder strTrans(i), "80" & "-" & Trim(Str(j)), rsCommodity!g_str80 & ""                          'Country of Manu
        TransactionBuilder strTrans(i), "81" & "-" & Trim(Str(j)), rsCommodity!g_str81 & ""                          'Harmonized Code
        TransactionBuilder strTrans(i), "82" & "-" & Trim(Str(j)), CStr(intQuantityNow) & ""                          'Quantity
        TransactionBuilder strTrans(i), "83" & "-" & Trim(Str(j)), rsCommodity!g_str83 & ""                          'Export license #
        TransactionBuilder strTrans(i), "84" & "-" & Trim(Str(j)), Format(rsCommodity!g_str84, "YYYYMMDD") & ""      'Export license Exp Date
        TransactionBuilder strTrans(i), "414" & "-" & Trim(Str(j)), rsCommodity!g_str414 & ""                        'Unit of Measure
        TransactionBuilder strTrans(i), "1030" & "-" & Trim(Str(j)), RemoveSpecial(ImpliedDecimal(rsCommodity!g_str1030, 6)) & ""       'Commodity Unit Value
        TransactionBuilder strTrans(i), "1275" & "-" & Trim(Str(j)), rsCommodity!g_str1275 & ""                        'Unit of Measure
        TransactionBuilder strTrans(i), "120" & "-" & Trim(Str(j)), rsCommodity!g_str120 & ""                        'Unit of Measure
        
        If IsNumeric(rsCommodity!g_str82) _
        And IsNumeric(rsCommodity!g_str1030) Then
            g_str119 = CDbl(g_str119) + intQuantityNow * CDbl(rsCommodity!g_str1030)
        End If
        
        ' Assign commodities to packages
        If i >= rsIntlMPS.RecordCount Then
            ' One package, or last package
            intQuantityToShip = intQuantityToShip = intQuantityNow
            If intQuantityToShip > 0 Then
                ' Ship all remaining of current commodity
                j = j + 1
                intQuantityNow = intQuantityToShip
            Else
                ' Ship next commodity
                rsCommodity.MoveNext
                If rsCommodity.EOF Then
                    intQuantityToShip = 1
                    intQuantityNow = 1
                Else
                    j = j + 1
                    intQuantityToShip = CLng(rsCommodity!g_str82 & "")
                    intQuantityNow = intQuantityToShip
                End If
            End If
        Else
            ' MPS package
            i = i + 1
            j = 1
            intQuantityToShip = intQuantityToShip - intQuantityNow
            If intQuantityToShip > 0 Then
                ' Ship some or all of current commodity
                If i >= rsIntlMPS.RecordCount Then
                    intQuantityNow = intQuantityToShip
                Else
                    intQuantityNow = 1
                End If
            Else
                ' Ship next commodity
                rsCommodity.MoveNext
                If rsCommodity.EOF Then
                    intQuantityToShip = 1
                    intQuantityNow = 1
                Else
                    intQuantityToShip = CLng(rsCommodity!g_str82 & "")
                    ' Ship some or all of this commodity
                    If i >= rsIntlMPS.RecordCount Then
                        intQuantityNow = intQuantityToShip
                    Else
                        intQuantityNow = 1
                    End If
                End If
            End If
        End If
        
    Loop
    
    If i < rsIntlMPS.RecordCount Then
        Err.Raise 12345, "BuildIPDShipTrans", "Insufficient commodities for " & rsIntlMPS.RecordCount & " packages."
    End If
    
    If g_str119 <> "" And g_str119 <> "0" Then
        TransactionBuilder strTrans(i), "119", g_str119
    End If
    
    For i = 1 To rsIntlMPS.RecordCount
    
        TransactionBuilder strTrans(i), 541, "NNNYNNNNN"                               'Open Ship Flags
        TransactionBuilder strTrans(i), 1355, g_str1355                                'IOR Facility Code
        
        ' TransactionBuilder strTrans(i), 4574, "2"
        
    '    'Added 9/13/05 for Alt Return Addr fields at the shipment level
        If g_str1586 = "Y" Then
            TransactionBuilder strTrans(i), 1586, g_str1586        'Print Alt Return flag
            TransactionBuilder strTrans(i), 1485, g_str1485        'Alt Return Contact
            TransactionBuilder strTrans(i), 1486, g_str1486        'Alt Return Company
            TransactionBuilder strTrans(i), 1487, g_str1487        'Alt Return Addr1
            TransactionBuilder strTrans(i), 1488, g_str1488        'Alt Return Addr2
            TransactionBuilder strTrans(i), 1489, g_str1489        'Alt Return City
            TransactionBuilder strTrans(i), 1490, g_str1490        'Alt Return State
            TransactionBuilder strTrans(i), 1491, g_str1491        'Alt Return Zip
            TransactionBuilder strTrans(i), 1492, g_str1492        'Alt Return Phone
            TransactionBuilder strTrans(i), 1585, g_str1585        'Alt Return Country
        End If
        
        TransactionBuilder strTrans(i), 99, ""                             'End of Transaction
        
    Next i
    
    Set BuildIPDShipTransColl = New Collection
    For i = 1 To rsIntlMPS.RecordCount
        Debug.Print strTrans(i)
        BuildIPDShipTransColl.Add strTrans(i)
    Next i

Release:
    If rsCommodity.State = adStateOpen Then
        rsCommodity.Close
    End If
    Set rsCommodity = Nothing
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildIPDShipTransColl"
    Resume Release
    
End Function

'---------------------------------------------------------------------------------------
' Procedure : BuildIPDConfirmTrans
' DateTime  : 3/17/2005
' Purpose   : Builds an IPD Confirm Transaction
'---------------------------------------------------------------------------------------
'
Public Function BuildIPDConfirmTrans() As String
    Dim strTrans As String
    
    On Error GoTo EH
    
    strTrans = ""
    With g_frmIPD
        
        TransactionBuilder strTrans, 0, "020"                                               'Trans type
        TransactionBuilder strTrans, 1, "IPD MAWB CONFRM" & .grdIPD.Columns("MAWB Trk#")    'TransID
        TransactionBuilder strTrans, 50, .grdIPD.Columns("Country")                         'Recip Country
        TransactionBuilder strTrans, 10, g_str10                                            'Acct #
        TransactionBuilder strTrans, 541, "NNNNNYNNY"                                       'Open Ship Flag
        TransactionBuilder strTrans, 1274, "18"                                             'Service Type
        TransactionBuilder strTrans, 1297, g_str1297                                        'Customer Inv #
        TransactionBuilder strTrans, 1355, .grdIPD.Columns("IOR Facility")                  'IOR Facility Code
        TransactionBuilder strTrans, 1358, g_str1358                                        'ITN/FTSR
        TransactionBuilder strTrans, 187, g_str187                                          'Label Type
        TransactionBuilder strTrans, 537, g_str537                                          'Thermal/Laser Label prt UNC/File Path
        
        '02/27/06 Added for future day shipping
        If IsDate(g_str24) Then
            TransactionBuilder strTrans, 24, Format(g_str24, "YYYYMMDD")                    'Ship Date Note yyyymmdd format, no punctuation
        Else
            TransactionBuilder strTrans, 24, g_str24                                        'Ship Date Note yyyymmdd format, no punctuation
        End If
        'Don't send field 1282 if label type is laser (DIB)
        If g_str187 <> "DIB" And g_str187 <> "PNG" Then
            TransactionBuilder strTrans, 1282, g_str1282                    'Printer Type Indicator
        End If
    End With
    If g_str1592 = "Y" Then
        TransactionBuilder strTrans, 119, RemoveSpecial(ImpliedDecimal(g_str119))   'Total Customs value of shipment
        TransactionBuilder strTrans, 79, g_str79                          'Label Type
    End If
    
    
    TransactionBuilder strTrans, 99, ""                 'End of Transaction
    
    BuildIPDConfirmTrans = strTrans
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildIPDConfirmTrans"
    
End Function
'---------------------------------------------------------------------------------------
' Procedure : BuildIPDDeleteTrans
' DateTime  : 10/26/2004
' Purpose   : Builds an IPD Delete Shipment Transaction
'---------------------------------------------------------------------------------------
'
Public Function BuildIPDDeleteTrans() As String
    Dim strTrans As String
    
    On Error GoTo EH
    
    strTrans = ""
    With g_frmIPD
        
        TransactionBuilder strTrans, 0, "020"                                           'Trans type
        TransactionBuilder strTrans, 1, "IPD MAWB DELETE" & .grdIPD.Columns("MAWB Trk#") 'TransID
        TransactionBuilder strTrans, 29, .grdIPD.Columns("MAWB Trk#")                   'MAWB Trk#
        TransactionBuilder strTrans, 50, .grdIPD.Columns("Country")                     'Recip Country
        TransactionBuilder strTrans, 10, g_str10                                            'Acct #
        TransactionBuilder strTrans, 541, "NNNNNNNYN"                                   'Open Ship Flag
        TransactionBuilder strTrans, 1274, "18"                                         'Service Type
        TransactionBuilder strTrans, 1355, .grdIPD.Columns("IOR Facility")              'IOR Facility Code
    
    End With
    
    TransactionBuilder strTrans, 99, ""                 'End of Transaction
    
    BuildIPDDeleteTrans = strTrans
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildIPDDeleteTrans"
End Function
'---------------------------------------------------------------------------------------
' Procedure : BuildDeleteTrans
' DateTime  : 2/18/2004
' Purpose   : Builds/returns a Delete transaction
'---------------------------------------------------------------------------------------
'
Public Function BuildDeleteTrans(ByVal strTrackNum As String) As String
    Dim strTrans As String
    
    On Error GoTo EH
    
    'Save the trk# to global var
    g_str29 = strTrackNum
    
    strTrans = ""
    TransactionBuilder strTrans, 0, "023"                   'Transaction type
    TransactionBuilder strTrans, 1, "Delete"                'Transaction ID
    TransactionBuilder strTrans, 29, g_str29                'Tracking #
    ' TransactionBuilder strTrans, 1123, g_str29                'Tracking #
    TransactionBuilder strTrans, 10, g_str10                'Acct Number
    TransactionBuilder strTrans, 99, ""                     'End of Transaction
    
    BuildDeleteTrans = strTrans
    
    Exit Function
EH:
     MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildDeleteTrans"

End Function
'---------------------------------------------------------------------------------------
' Procedure : BuildCRNDeleteTrans
' DateTime  : 11/1/2004
' Purpose   : Deletes a trk#
'---------------------------------------------------------------------------------------
'
Public Function BuildCRNDeleteTrans(ByVal strTrackNum As String, ByVal strIOR As String, ByVal strCountry As String) As String
    Dim strTrans As String
    
    On Error GoTo EH
    
    'Save the trk# to global var
    g_str29 = strTrackNum
    
    'Set IPD flag to True
    g_blnIPD = True
    
    strTrans = ""
    TransactionBuilder strTrans, 0, "020"                   'Transaction type
    TransactionBuilder strTrans, 1, "IPD CRN DELETE "       'Transaction ID
    TransactionBuilder strTrans, 29, g_str29                'Tracking #
    TransactionBuilder strTrans, 50, strCountry             'Country Code
    TransactionBuilder strTrans, 10, g_str10                'Acct #
'    TransactionBuilder strTrans, 498, g_str498              'Meter #
    TransactionBuilder strTrans, 541, "NNNNNNYNN"           'Open Ship Flags
    TransactionBuilder strTrans, 1274, "18"                 'Tracking #
    TransactionBuilder strTrans, 1355, strIOR               'Acct Number
    TransactionBuilder strTrans, 99, ""                     'End of Transaction
    
    BuildCRNDeleteTrans = strTrans
    
    Exit Function
EH:
     MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildCRNDeleteTrans"

End Function
'---------------------------------------------------------------------------------------
' Procedure : BuildLabelRepintTrans
' DateTime  : 11/3/2004
' Purpose   : Reprints a label
'---------------------------------------------------------------------------------------
'
Public Function BuildLabelReprintTrans(ByVal strTrackNum As String) As String
        Dim strTrans As String
    
    On Error GoTo EH
    
    strTrans = ""
    TransactionBuilder strTrans, 0, "095"                   'Transaction type
    TransactionBuilder strTrans, 1, "Label Reprint"         'Transaction ID
    TransactionBuilder strTrans, 29, strTrackNum            'Tracking #
    TransactionBuilder strTrans, 537, g_str537              'Printer UNC
    TransactionBuilder strTrans, 99, ""                     'End of Transaction
    
    BuildLabelReprintTrans = strTrans
    
    Exit Function
EH:
     MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildLabelReprintTrans"

End Function
'---------------------------------------------------------------------------------------
' Procedure : SendData
' DateTime  : 2/18/2004
' Purpose   : Sends the strTrans passed to FXRS
'---------------------------------------------------------------------------------------
'
Public Sub SendData(ByVal strTrans As String)
    
    On Error GoTo EH
    
    If strTrans = "" Then Exit Sub
    
    DebugPrint "SendData, " & strTrans
    
    If Not BeforeShipTrans(strTrans) Then
        MsgBox "Transaction not accepted by integration (BeforeShipTrans)", vbCritical, "modFXRSTransactions:SendData"
        Exit Sub
    End If
    
    DebugPrint "SendData2, " & strTrans
    
    ' 2008-03-25, JFW, Save ship trans to global variable to save in client db
    If Left(strTrans, 7) = "0,""020""" Then
        g_strRepeatTrans = strTrans
    End If
    
    '01/10/06 Moved ProcessTransIn to frmDebug
    If g_blnDebug Then
        With frmDebug
            .Show vbModeless, frmShip
            .txtTransIn = strTrans
            '6/09/06 Clear Output trans when new Input trans received
            '.txtTransOut = ""
            '6/09/06 Added Auto-Send
            If .chkAutoSend = 1 Then .cmdSend = True
        End With
    Else
        If frmShip.wscFXRS.State = 7 Then
            'Send the transaction for each pkg.
            frmShip.wscFXRS.SendData strTrans
        Else
            frmShip.StatusBar1.Panels(2) = "Connect to server?"
        End If
    End If
    
    Exit Sub
EH:
     MsgBox Err.Description, vbCritical, "modFXRSTransactions:SendData"
     If False Then
        Resume
    End If
     
End Sub
'---------------------------------------------------------------------------------------
' Procedure : BuildTrkNumRequest
' DateTime  : 3/2/2005
' Purpose   : FXRS Tracking # request
'---------------------------------------------------------------------------------------
'
Public Function BuildTrkNumRequest(ByVal strOrderID As String, ByVal strType As String) As String
    
    Dim strTrans As String
    
    On Error GoTo EH
    
    TransactionBuilder strTrans, 0, "004"                   'Transaction type
    TransactionBuilder strTrans, 1, strOrderID              'Transaction ID
    TransactionBuilder strTrans, 498, g_str498              'Acct Number
    TransactionBuilder strTrans, 499, strType               'Trk# Type
    TransactionBuilder strTrans, 99, ""                     'End of Transaction
    
    BuildTrkNumRequest = strTrans
    
    Exit Function
EH:
     MsgBox Err.Description, vbCritical, "modFXRSTransactions.BuildTrkNumRequest"

End Function
'---------------------------------------------------------------------------------------
' Module    : BuildIDGFlds
' DateTime  : 8/18/2005
' Author    : Chris Elwell
' Purpose   : Builds and returns fields required for ADG.
'---------------------------------------------------------------------------------------
'
Public Function BuildIDGFlds(ByVal strTrans As String) As String
    
    On Error GoTo EH
    
'    TransactionBuilder strTrans, 1331, g_str1331                            'DG Flag
'    TransactionBuilder strTrans, 1493, "N"                                  'DG Form Print Flag
'    TransactionBuilder strTrans, 1918, "Name"                               'DG Name of Signatory
'    TransactionBuilder strTrans, 1922, "City, State"                        'DG Place of Signatory
'    TransactionBuilder strTrans, 484, "8004249300"                          'DG Emergency Phone #
'    TransactionBuilder strTrans, 485, "Shipping Clerk"                      'DG Title of Signatory
'    TransactionBuilder strTrans, 1932, "1"                                  'DG Commodity Count
'    TransactionBuilder strTrans, 451, "3090"                                'DG UN #
'    TransactionBuilder strTrans, 456, "1"                                   'DG Number of Units
'    TransactionBuilder strTrans, 461, "4G Box"                              'DG Packing Type
'    TransactionBuilder strTrans, 466, "1"                                   'DG Quantity
'    TransactionBuilder strTrans, 471, "g"                                   'DG Unit of Measure
'    TransactionBuilder strTrans, 476, "903"                                 'DG Packing Instructions
'    TransactionBuilder strTrans, 488, "Y"                                   'DG Cargo Aircraft Only Field
'    TransactionBuilder strTrans, 489, "II"                                  'DG Packing Group
'    TransactionBuilder strTrans, 1903, "Lithium Batteries"                  'DG Proper Shipping Name

    BuildIDGFlds = strTrans & frmDG.BuildFields
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildIDGFlds"
    
End Function
'---------------------------------------------------------------------------------------
' Module    : BuildADGFlds
' DateTime  : 8/18/2005
' Author    : Chris Elwell
' Purpose   : Builds and returns fields required for IDG.
'---------------------------------------------------------------------------------------
'
Public Function BuildADGFlds(ByVal strTrans As String) As String
    
    On Error GoTo EH
    
'    TransactionBuilder strtrans, 1331, g_str1331                            'DG Flag
'    TransactionBuilder strtrans, 1493, "N"                                  'DG Form Print Flag
'    TransactionBuilder strtrans, 1918, "Name"                               'DG Name of Signatory
'    TransactionBuilder strtrans, 1922, "City, State"                        'DG Place of Signatory
'    TransactionBuilder strtrans, 484, "8004249300"                          'DG Emergency Phone #
'    TransactionBuilder strtrans, 485, "Shipping Clerk"                      'DG Title of Signatory
'    TransactionBuilder strtrans, 1932, "1"                                  'DG Commodity Count
'    TransactionBuilder strtrans, 451, "1263"                                'DG UN #
'    TransactionBuilder strtrans, 456, "1"                                   'DG Number of Units
'    TransactionBuilder strtrans, 461, "STEELDRUM"                           'DG Packing Type
'    TransactionBuilder strtrans, 466, "175"                                 'DG Quantity
'    TransactionBuilder strtrans, 471, "L"                                   'DG Unit of Measure
'    TransactionBuilder strtrans, 476, "Y309"                                'DG Packing Instructions
'    TransactionBuilder strtrans, 489, "III"                                 'DG Packing Group
'    TransactionBuilder strtrans, 1903, "PAINT"                              'DG Proper Shipping Name

    BuildADGFlds = strTrans & frmDG.BuildFields
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildADGFlds"
    
End Function

'---------------------------------------------------------------------------------------
' Module    : BuildHazMatFlds
' DateTime  : 8/18/2005
' Author    : Chris Elwell
' Purpose   : Builds and returns fields required for HazMat.
'---------------------------------------------------------------------------------------
'
Public Function BuildHazMatFlds(ByVal strTrans As String) As String
    
    On Error GoTo EH
    
    '20071016-02 Added Ha-Mat OP-900 fields. Still support label w/no OP-900
'    TransactionBuilder strTrans, 1331, "Y"                                  'DG Flag
'    TransactionBuilder strTrans, 1493, g_str1493                            'DG Form Print Flag
'    TransactionBuilder strTrans, 484, g_str484                                                              'DG Emergency Phone #
'    TransactionBuilder strTrans, 451, IIf(g_str1493 = "Y", g_str451, "3090")                                'DG UN #
'    TransactionBuilder strTrans, 466, IIf(g_str1493 = "Y", RemoveSpecial(ImpliedDecimal(g_str466)), "1")    'DG Quantity
'    TransactionBuilder strTrans, 471, IIf(g_str1493 = "Y", g_str471, "g")                                   'DG Unit of Measure
'    TransactionBuilder strTrans, 489, IIf(g_str1493 = "Y", g_str489, "II")                                  'DG Packing Group
'    TransactionBuilder strTrans, 492, IIf(g_str1493 = "Y", g_str492, "")                                    'Haz Class
'    TransactionBuilder strTrans, 1903, IIf(g_str1493 = "Y", g_str1903, "Lithium Batteries")                 'DG Proper Shipping Name
'    TransactionBuilder strTrans, 3072, IIf(g_str1493 = "Y", g_str3072, "")                                  'DG Proper Shipping Name
    
    BuildHazMatFlds = strTrans & frmDG.BuildHazMatFlds
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildHazMatFlds"
    
End Function
'---------------------------------------------------------------------------------------
' Module    : BuildAddrVerifyTrans
' DateTime  : 9/7/2005
' Author    : Chris Elwell
' Purpose   : Builds and returns Addr Verify 415 transaction.
'---------------------------------------------------------------------------------------
'
Public Function BuildAddrVerifyTrans(ByVal str11 As String, ByVal str13 As String, _
                                     ByVal str14 As String, ByVal str15 As String, _
                                     ByVal str16 As String, ByVal str17 As String, _
                                     ByVal str50 As String) As String
                                     
    Dim strTrans As String

    On Error GoTo EH
    
    'Replace statements below reduce the number of "Address modified to achieve a match"
    'soft errors.
    str13 = Replace(str13, "Street", "St")
    str13 = Replace(str13, "Road", "Rd")
    str13 = Replace(str13, "Avenue", "Ave")
    str13 = Replace(str13, "Place", "Pl")
    str13 = Replace(str13, "Court", "Ct")
    str13 = Replace(str13, "Cove", "Cv")
    str13 = Replace(str13, "Circle", "Cir")
    str13 = Replace(str13, "Drive", "Dr")
    str13 = Replace(str13, "Lane", "Ln")
    str13 = Replace(str13, "Parkway", "Pkwy")
    str13 = Replace(str13, "Boulevard", "Blvd")
    str13 = Replace(str13, "Trail", "Trl")
    str13 = Replace(str13, ".", " ")
    str13 = Replace(str13, "North", "N")
    str13 = Replace(str13, "South", "S")
    str13 = Replace(str13, "East", "E")
    str13 = Replace(str13, "West", "W")
    'Added 10/17/05
    str13 = Replace(str13, "Landing", "Lndg")
    
    str14 = Replace(str14, "Suite", "Ste")
    str14 = Replace(str14, "Room", "Rm")
    str14 = Replace(str14, "Floor", "Fl")
    str14 = Replace(str14, ".", " ")
    
    'Added 10/17/05 to remove period from City, e.g. Ft. Lauderdale
    str15 = Replace(str15, ".", " ")
    
    strTrans = ""
    TransactionBuilder strTrans, 0, "415"                           'Transaction type
    TransactionBuilder strTrans, 1, "AddrVerify"                    'Transaction ID
    TransactionBuilder strTrans, 498, g_str498                      'Meter #
    TransactionBuilder strTrans, 11, str11                          'Recipient Company
    TransactionBuilder strTrans, 13, str13                          'Recipient Addr1
    TransactionBuilder strTrans, 14, str14                          'Recipient Addr2
    TransactionBuilder strTrans, 15, str15                          'Recipient City
    TransactionBuilder strTrans, 16, str16                          'Recipient State
    TransactionBuilder strTrans, 17, str17                          'Recipient Zip
    TransactionBuilder strTrans, 50, str50                          'Country
    TransactionBuilder strTrans, 1601, "2"                          'Max candidates
    TransactionBuilder strTrans, 99, ""                             'End of Transaction

    BuildAddrVerifyTrans = strTrans
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, "modFXRSTransactions:BuildAddrVerifyTrans"
    
End Function


